Aktueller Stand
This commit is contained in:
27
backend/node_modules/fastify/examples/benchmark/webstream.js
generated
vendored
Normal file
27
backend/node_modules/fastify/examples/benchmark/webstream.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'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}`)
|
||||
})
|
||||
Reference in New Issue
Block a user