Created
October 20, 2022 16:47
-
-
Save RafaelGSS/52e14e8483a9e808f08140f9a6a3cf22 to your computer and use it in GitHub Desktop.
Undici v19 support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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