最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - No response sent from an api - Stack Overflow

programmeradmin1浏览0评论

I don't receive any response on client side. This is the server side api:

export async function GET(request: NextRequest) {
    
    const client = new ftp.Client();
    client.ftp.verbose = true;

    try {
        console.log("Connecting to FTP server...");
        await client.access(ftpConfig);

        const remoteFilePath = "/public_html/images/data/gallery.json";

        const chunks: Uint8Array[] = [];
        const writableStream = new Writable();

        writableStream._write = () => {};

        writableStream.on("data", (chunk) => {
            chunks.push(chunk);
        });

        console.log(`Downloading file from: ${remoteFilePath}`);

        await client.downloadTo(writableStream, remoteFilePath);

        console.log("File downloaded successfully.");

        const fileContent = Buffer.concat(chunks).toString("utf8");

        console.log("File content:", fileContent);

        const jsonData = JSON.parse(fileContent);

        console.log("File downloaded successfully.");

        return NextResponse.json({ success: true, data: jsonData, message: "File downloaded successfully." });
    } catch (error) {
        console.error("FTP connection error:", error);
        return NextResponse.json({ success: false, message: "FTP connection error." });
    } finally {
        client.close();
    }
}

Client side I have this:

useEffect(()=>{
const fetchImagesData = async () => {
const response = await fetch("api/galleryData")
const data = await response.json()
}, [])

And no log is displaying.

Also, I try to download the file to read it is that the correct way ?

发布评论

评论列表(0)

  1. 暂无评论