Prerequisites
Fastify version
4.25.2
Plugin version
No response
Node.js version
20.10
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
I make a fetch call on my Fastify server and I want to return the response from that fetch call as the response of my Fastify route as a stream.
I thought this would work since Fastify has stream docs (https://fastify.dev/docs/latest/Reference/Reply/#streams), but it does not.
Steps to Reproduce
Clone this github repo: https://github.com/TJBlackman/fastify-stream-test
Install dependencies and run the project:
Make requests to the API:
For the sake of completeness, here is the demo server file you could copy/paste if you want.
const fastify = require("fastify")({ logger: true });
// return JSON from SWAPI - works!
fastify.get("/api/json", async (request, reply) => {
const response = await fetch("https://swapi.dev/api/people/1/");
const json = await response.json();
return reply.send(json);
});
// return stream from SWAPI - doesn't work
fastify.get("/api/stream", async (request, reply) => {
const response = await fetch("https://swapi.dev/api/people/1/");
return reply.send(response.body);
});
fastify.listen({ port: 3000 }, (err) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
});
Expected Behavior
The streamed response should be the same as the JSON response.
Prerequisites
Fastify version
4.25.2
Plugin version
No response
Node.js version
20.10
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
I make a fetch call on my Fastify server and I want to return the response from that fetch call as the response of my Fastify route as a stream.
I thought this would work since Fastify has stream docs (https://fastify.dev/docs/latest/Reference/Reply/#streams), but it does not.
Steps to Reproduce
Clone this github repo: https://github.com/TJBlackman/fastify-stream-test
Install dependencies and run the project:
Make requests to the API:
For the sake of completeness, here is the demo server file you could copy/paste if you want.
Expected Behavior
The streamed response should be the same as the JSON response.