FastifyBackend
此内容尚不支持你的语言。
Defined in: src/http/backend/FastifyBackend.ts:41
Fastify-based default HTTP backend. Leans on Fastify for fast routing,
body parsing (including raw-body support), and its plugin ecosystem.
The directives DSL compiles down to plain Fastify route registrations —
user code never interacts with Fastify types unless they explicitly opt
in via backend.withPlugin(...).
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FastifyBackend(
options?):FastifyBackend
Defined in: src/http/backend/FastifyBackend.ts:51
Parameters
Section titled “Parameters”options?
Section titled “options?”object = ...
Returns
Section titled “Returns”FastifyBackend
Properties
Section titled “Properties”
readonlyname:"fastify"='fastify'
Defined in: src/http/backend/FastifyBackend.ts:42
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”listen()
Section titled “listen()”listen(
host,port):Promise<ServerBinding>
Defined in: src/http/backend/FastifyBackend.ts:116
Start listening. Returns a ServerBinding with the actual bound port.
Parameters
Section titled “Parameters”string
number
Returns
Section titled “Returns”Promise<ServerBinding>
Implementation of
Section titled “Implementation of”registerRoute()
Section titled “registerRoute()”registerRoute(
route):void
Defined in: src/http/backend/FastifyBackend.ts:69
Register all routes before listen is called. Duplicate paths must be rejected.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”HttpServerBackend.registerRoute
registerWebSocket()
Section titled “registerWebSocket()”registerWebSocket(
reg):void
Defined in: src/http/backend/FastifyBackend.ts:86
Optional capability: register a WebSocket endpoint. Backends that
implement this support websocket() routes; absence is detected by
HttpExtension.bind and reported as a clear error.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”HttpServerBackend.registerWebSocket
setDefaultResponseHeaders()
Section titled “setDefaultResponseHeaders()”setDefaultResponseHeaders(
headers):void
Defined in: src/http/backend/FastifyBackend.ts:101
Optional: replace the header map the backend writes ahead of every response it emits — including the error, not-found and upgrade-reject responses no middleware ever sees. A response’s own header must still win, so these are written first and overwritten, not merged over.
HttpExtension wires withSecurityHeaders(...) here and passes {}
for the opt-out. It is only called when that was configured: a backend
comes with its own default (DEFAULT_RESPONSE_SECURITY_HEADERS
for the shipped ones), so an untouched builder must not overwrite it.
Parameters
Section titled “Parameters”headers
Section titled “headers”Readonly<Record<string, string>>
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”HttpServerBackend.setDefaultResponseHeaders
setErrorHandler()
Section titled “setErrorHandler()”setErrorHandler(
handler):void
Defined in: src/http/backend/FastifyBackend.ts:105
Optional: register a last-resort error handler. It MUST see both
errors thrown by route handlers AND backend-internal errors (body
parsing, etc.); if it throws, the backend falls back to its default
error mapping. HttpExtension wires withErrorHandler here.
Parameters
Section titled “Parameters”handler
Section titled “handler”(err, request) => HttpResponse | Promise<HttpResponse>
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”HttpServerBackend.setErrorHandler
setNotFound()
Section titled “setNotFound()”setNotFound(
handler):void
Defined in: src/http/backend/FastifyBackend.ts:93
Optional: register a method-agnostic not-found handler, invoked for
any request that matched no route (including unmatched OPTIONS/HEAD).
HttpExtension wires fallback() here. If the handler throws, the
backend applies its default error mapping.
Parameters
Section titled “Parameters”handler
Section titled “handler”(request) => HttpResponse | Promise<HttpResponse>
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”withPlugin()
Section titled “withPlugin()”withPlugin(
plugin,options?):Promise<void>
Defined in: src/http/backend/FastifyBackend.ts:65
Escape hatch: register a native Fastify plugin (e.g. @fastify/cors).
Parameters
Section titled “Parameters”plugin
Section titled “plugin”unknown
options?
Section titled “options?”object
Returns
Section titled “Returns”Promise<void>
