Home / File/ serverFactory.test-d.ts — fastify Source File

serverFactory.test-d.ts — fastify Source File

Architecture documentation for serverFactory.test-d.ts, a typescript file in the fastify codebase. 3 imports, 0 dependents.

File typescript CoreKernel InstanceFactory 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  31d2b9b4_ad31_ebb2_2e0f_15453ae753b4["serverFactory.test-d.ts"]
  2bf9986b_b7fb_0c78_f075_72fbe6f4672b["fastify.js"]
  31d2b9b4_ad31_ebb2_2e0f_15453ae753b4 --> 2bf9986b_b7fb_0c78_f075_72fbe6f4672b
  bd94e3ff_2705_51a0_bac0_884f2c38b615["node:http"]
  31d2b9b4_ad31_ebb2_2e0f_15453ae753b4 --> bd94e3ff_2705_51a0_bac0_884f2c38b615
  1741b237_9033_f1d9_f91f_94ad04e621d4["tsd"]
  31d2b9b4_ad31_ebb2_2e0f_15453ae753b4 --> 1741b237_9033_f1d9_f91f_94ad04e621d4
  style 31d2b9b4_ad31_ebb2_2e0f_15453ae753b4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fastify, { FastifyServerFactory } from '../../fastify'
import * as http from 'node:http'
import { expectType } from 'tsd'

// Custom Server
type CustomType = void
interface CustomIncomingMessage extends http.IncomingMessage {
  fakeMethod?: () => CustomType;
}

interface CustomServerResponse extends http.ServerResponse {
  fakeMethod?: () => CustomType;
}

const serverFactory: FastifyServerFactory<http.Server> = (handler, opts) => {
  const server = http.createServer((req: CustomIncomingMessage, res: CustomServerResponse) => {
    req.fakeMethod = () => {}
    res.fakeMethod = () => {}

    handler(req, res)
  })

  return server
}

// The request and reply objects should have the fakeMethods available (even though they may be undefined)
const customServer = fastify<http.Server, CustomIncomingMessage, CustomServerResponse>({ serverFactory })

customServer.get('/', function (request, reply) {
  if (request.raw.fakeMethod) {
    expectType<CustomType>(request.raw.fakeMethod())
  }

  if (reply.raw.fakeMethod) {
    expectType<CustomType>(reply.raw.fakeMethod())
  }
})

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does serverFactory.test-d.ts do?
serverFactory.test-d.ts is a source file in the fastify codebase, written in typescript. It belongs to the CoreKernel domain, InstanceFactory subdomain.
What functions are defined in serverFactory.test-d.ts?
serverFactory.test-d.ts defines 2 function(s): CustomType, serverFactory.
What does serverFactory.test-d.ts depend on?
serverFactory.test-d.ts imports 3 module(s): fastify.js, node:http, tsd.
Where is serverFactory.test-d.ts in the architecture?
serverFactory.test-d.ts is located at test/types/serverFactory.test-d.ts (domain: CoreKernel, subdomain: InstanceFactory, directory: test/types).

Analyze Your Own Codebase

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

Try Supermodel Free