Stream from nextjs python endpoint on servless function is not "streaming"
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
Hey, I have a python endpoint that gets built by nextjs and deployed with vercel together with the rest of my app.
The python code returns a stream, which works as expected when I run it and call directly the server running through uvicorn locally.
But when I deploy or locally I try to call it through nextjs/vercel using this config
the response does not stream to the application.
What I noticed is that the rewrite response connection header is set as closed instead of keep-alive. Even if it says "closed" after the computation is done and there was no response initially, the response body come back as a list of chucks that all arrives at the same time.
It seems that the rewrite does not send back the correct response header that the endpoint is sending. Any idea on possible solutions?
Thank you!
The python code returns a stream, which works as expected when I run it and call directly the server running through uvicorn locally.
But when I deploy or locally I try to call it through nextjs/vercel using this config
/** @type {import('next').NextConfig} */
const nextConfig = {
rewrites: async () => {
return [
{
source: "/api/:path*",
destination:
process.env.NODE_ENV === "development"
? "http://127.0.0.1:8001/api/:path*"
: "/api/",
}
};
module.exports = nextConfig;the response does not stream to the application.
What I noticed is that the rewrite response connection header is set as closed instead of keep-alive. Even if it says "closed" after the computation is done and there was no response initially, the response body come back as a list of chucks that all arrives at the same time.
It seems that the rewrite does not send back the correct response header that the endpoint is sending. Any idea on possible solutions?
Thank you!