Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Created October 20, 2022 16:47
Show Gist options
  • Save RafaelGSS/52e14e8483a9e808f08140f9a6a3cf22 to your computer and use it in GitHub Desktop.
Save RafaelGSS/52e14e8483a9e808f08140f9a6a3cf22 to your computer and use it in GitHub Desktop.
Undici v19 support
const Fastify = require('./fastify')
const { Client } = require('undici')
const assert = require('assert')
const fastify = Fastify({
return503OnClosing: true,
forceCloseConnections: false
})
fastify.get('/', (req, reply) => {
fastify.close()
reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, async err => {
if (err) throw err
const instance = new Client('http://localhost:' + fastify.server.address().port, {
pipelining: 1
})
const codes = [200, 503]
for (const code of codes) {
instance.request(
{ path: '/', method: 'GET' }
).then(data => {
console.log('done', data.statusCode)
assert.equal(data.statusCode, code)
}).catch((e) => {
console.error('fail', e)
})
}
instance.close(() => {
console.log('done')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment