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
版权声明:本文标题:javascript - No response sent from an api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744761964a2623805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论