Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,12 +1,11 @@
'use strict'
const t = require('tap')
const test = t.test
const { test } = require('node:test')
const Fastify = require('../..')
const https = require('node:https')
const dns = require('node:dns').promises
const sget = require('simple-get').concat
const { buildCertificate } = require('../build-certificate')
const { Agent } = require('undici')
async function setup () {
await buildCertificate()
@@ -14,11 +13,11 @@ async function setup () {
const localAddresses = await dns.lookup('localhost', { all: true })
test('Should support a custom https server', { skip: localAddresses.length < 1 }, async t => {
t.plan(4)
t.plan(5)
const fastify = Fastify({
serverFactory: (handler, opts) => {
t.ok(opts.serverFactory, 'it is called once for localhost')
t.assert.ok(opts.serverFactory, 'it is called once for localhost')
const options = {
key: global.context.key,
@@ -34,29 +33,25 @@ async function setup () {
}
})
t.teardown(fastify.close.bind(fastify))
t.after(() => { fastify.close() })
fastify.get('/', (req, reply) => {
t.ok(req.raw.custom)
t.assert.ok(req.raw.custom)
reply.send({ hello: 'world' })
})
await fastify.listen({ port: 0 })
await new Promise((resolve, reject) => {
sget({
method: 'GET',
url: 'https://localhost:' + fastify.server.address().port,
rejectUnauthorized: false
}, (err, response, body) => {
if (err) {
return reject(err)
const result = await fetch('https://localhost:' + fastify.server.address().port, {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false
}
t.equal(response.statusCode, 200)
t.same(JSON.parse(body), { hello: 'world' })
resolve()
})
})
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
})
}