Home / Function/ setup() — fastify Function Reference

setup() — fastify Function Reference

Architecture documentation for the setup() function in custom-https-server.test.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  81ae100f_bb98_269c_24de_3d8c80c88bb4["setup()"]
  3b9912ab_b25a_28d5_77bd_b26a70c3cc3c["custom-https-server.test.js"]
  81ae100f_bb98_269c_24de_3d8c80c88bb4 -->|defined in| 3b9912ab_b25a_28d5_77bd_b26a70c3cc3c
  style 81ae100f_bb98_269c_24de_3d8c80c88bb4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

test/https/custom-https-server.test.js lines 10–56

async function setup () {
  await buildCertificate()

  const localAddresses = await dns.lookup('localhost', { all: true })

  test('Should support a custom https server', { skip: localAddresses.length < 1 }, async t => {
    t.plan(5)

    const fastify = Fastify({
      serverFactory: (handler, opts) => {
        t.assert.ok(opts.serverFactory, 'it is called once for localhost')

        const options = {
          key: global.context.key,
          cert: global.context.cert
        }

        const server = https.createServer(options, (req, res) => {
          req.custom = true
          handler(req, res)
        })

        return server
      }
    })

    t.after(() => { fastify.close() })

    fastify.get('/', (req, reply) => {
      t.assert.ok(req.raw.custom)
      reply.send({ hello: 'world' })
    })

    await fastify.listen({ port: 0 })

    const result = await fetch('https://localhost:' + fastify.server.address().port, {
      dispatcher: new Agent({
        connect: {
          rejectUnauthorized: false
        }
      })
    })
    t.assert.ok(result.ok)
    t.assert.strictEqual(result.status, 200)
    t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
  })
}

Domain

Subdomains

Frequently Asked Questions

What does setup() do?
setup() is a function in the fastify codebase, defined in test/https/custom-https-server.test.js.
Where is setup() defined?
setup() is defined in test/https/custom-https-server.test.js at line 10.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free