Files
simple-mail-cleaner/backend/node_modules/fastify/examples/benchmark/webstream.js
2026-01-22 19:05:45 +01:00

28 lines
561 B
JavaScript

'use strict'
const fastify = require('../../fastify')({
logger: false
})
const payload = JSON.stringify({ hello: 'world' })
fastify.get('/', function (req, reply) {
const stream = new ReadableStream({
start (controller) {
controller.enqueue(payload)
controller.close()
}
})
return new Response(stream, {
status: 200,
headers: {
'content-type': 'application/json; charset=utf-8'
}
})
})
fastify.listen({ port: 3000 }, (err, address) => {
if (err) throw err
console.log(`Server listening on ${address}`)
})