MCPcopy
hub / github.com/fastify/fastify / getHandler

Function getHandler

test/types/request.tst.ts:63–111  ·  view source on GitHub ↗
(request, _reply)

Source from the content-addressed store, hash-verified

61}
62
63const getHandler: RouteHandler = function (request, _reply) {
64 expect(request.url).type.toBe<string>()
65 expect(request.originalUrl).type.toBe<string>()
66 expect(request.method).type.toBe<string>()
67 expect(request.routeOptions).type.toBe<Readonly<RequestRouteOptions>>()
68 expect(request.is404).type.toBe<boolean>()
69 expect(request.hostname).type.toBe<string>()
70 expect(request.host).type.toBe<string>()
71 expect(request.port).type.toBe<number | null>()
72 expect(request.ip).type.toBe<string>()
73 expect(request.ips).type.toBe<string[] | undefined>()
74 expect(request.raw).type.toBe<RawRequestDefaultExpression>()
75 expect(request.body).type.toBe<RequestBodyDefault>()
76 expect(request.params).type.toBe<RequestParamsDefault>()
77 expect(request.routeOptions.config).type.toBe<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>()
78 expect(request.routeOptions.schema).type.toBe<FastifySchema | undefined>()
79 expect(request.routeOptions.handler).type.toBe<RouteHandlerMethod>()
80 expect(request.routeOptions.url).type.toBe<string | undefined>()
81 expect(request.routeOptions.version).type.toBe<string | undefined>()
82
83 expect(request.headers).type.toBe<RequestHeadersDefault & RawRequestDefaultExpression['headers']>()
84 request.headers = {}
85
86 expect(request.query).type.toBe<RequestQuerystringDefault>()
87 expect(request.id).type.toBe<string>()
88 expect(request.log).type.toBe<FastifyBaseLogger>()
89 expect(request.socket).type.toBe<RawRequestDefaultExpression['socket']>()
90 expect(request.signal).type.toBe<AbortSignal>()
91 expect(request.validationError).type.toBe<Error & { validation: any; validationContext: string } | undefined>()
92 expect(request.server).type.toBe<FastifyInstance>()
93 expect(request.getValidationFunction).type.toBeAssignableTo<
94 (httpPart: HTTPRequestPart) => ExpectedGetValidationFunction | undefined
95 >()
96 expect(request.getValidationFunction).type.toBeAssignableTo<
97 (schema: { [key: string]: unknown }) => ExpectedGetValidationFunction | undefined
98 >()
99 expect(request.getValidationFunction('body')).type.toBe<ValidationFunction | undefined>()
100 expect(request.getValidationFunction({ type: 'object' })).type.toBe<ValidationFunction | undefined>()
101 expect(request.validateInput).type.toBeAssignableTo<
102 (input: { [key: string]: unknown }, schema: { [key: string]: unknown }, httpPart?: HTTPRequestPart) => boolean
103 >()
104 expect(request.validateInput).type.toBeAssignableTo<
105 (input: { [key: string]: unknown }, httpPart?: HTTPRequestPart) => boolean
106 >()
107 expect(request.getDecorator<string>('foo')).type.toBe<string>()
108 expect(request.setDecorator('foo', 'hello')).type.toBe<void>()
109 expect(request.setDecorator<string>('foo', 'hello')).type.toBe<void>()
110 expect(request.setDecorator<string>).type.not.toBeCallableWith('foo', true)
111}
112
113const getHandlerWithCustomLogger: RouteHandlerMethod<
114 RawServerDefault,

Callers

nothing calls this directly

Calls 3

getValidationFunctionMethod · 0.80
setDecoratorMethod · 0.80
getDecoratorMethod · 0.65

Tested by

no test coverage detected