admin管理员组

文章数量:1391749

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 ?

本文标签: javascriptNo response sent from an apiStack Overflow