Skip to content

Type Alias: FastifyHTTPEntrypointOptions ​

说明

本页由源码中的注释生成,内容为英文。

FastifyHTTPEntrypointOptions = InterfaceListeningOptions & object

The options of fastifyHTTPEntrypoint; with interface, the server listens on network interfaces instead of an address (see InterfaceListeningOptions).

Type Declaration ​

before? ​

optional before?: (app, context) => void | Promise<void>

Run before the action routes are added, to register the application's own plugins, hooks and routes. A failure fails the entrypoint start.

Parameters ​

app ​

FastifyInstance

context ​

FastifyHookContext

Returns ​

void | Promise<void>

body? ​

optional body?: object

The content types listed in text (application/sdp, or text/* for a whole type) are read as text: the actions get those bodies as a string, the body property of their input; the bodyLimit of fastify applies. Fastify answers a body of a type it does not parse (JSON and text/plain are parsed) with an error (415).

Default ​

ts
none

body.text? ​

optional text?: string[]

fallback? ​

optional fallback?: (request, reply) => unknown

The handler of the requests that match no route and whose path is outside the action prefixes, such as the pages of a web application. The unmatched requests inside the action prefixes, and all of them without a fallback, are answered with a RouteNotFoundException (404).

Parameters ​

request ​

FastifyRequest

reply ​

FastifyReply

Returns ​

unknown

fastify? ​

optional fastify?: FastifyInstance | FastifyServerOptions

An existing fastify instance to add the action routes to, or the options of the instance to create (bodyLimit, trustProxy, logger…). The adapter closes the instance when it stops, a given one included.

Default ​

ts
a new fastify instance with its default options (a body limit of 1 MiB)

heartbeat? ​

optional heartbeat?: number

The interval between the comments keeping the event streams (EventsResult) alive through the proxies, in milliseconds.

Default ​

ts
15000

host? ​

optional host?: string

The host or address the server listens on; excludes interface.

Default ​

every interface, as the other HTTP adapters (::, or 0.0.0.0 without IPv6)

input? ​

optional input?: (request) => Record<string, unknown>

Build an action's input from a request. The route parameters are always merged over its result.

Parameters ​

request ​

FastifyRequest

Returns ​

Record<string, unknown>

Default ​

the query parameters, then the properties of an object body over them (an array body is ignored), or, for a body of one of the text types of the body option, its text as body

listening? ​

optional listening?: (server, listeners?) => void | Promise<void>

Run once the server listens (on an address), or once the listeners of the interfaces are made (with interface): the server itself does not listen then, its address() is null; the listeners give the port, the addresses and whether the other interfaces are refused (enforced). A failure fails the entrypoint start.

Parameters ​

server ​

Server

listeners? ​

IInterfaceListener[]

Returns ​

void | Promise<void>

middlewares? ​

optional middlewares?: MiddlewareDefinition[]

The middlewares of this adapter's actions, run after the entrypoint's global middlewares.

name? ​

optional name?: string

The adapter name, to tell apart several HTTP adapters of one entrypoint.

port? ​

optional port?: number

The port the server listens on; 0 picks a random free port. The entrypoint fails to start when the port is in use.

Default ​

ts
80

respond? ​

optional respond?: FastifyResponder

How the results and the errors of the actions are written.

Default ​

ts
FastifyJSONResponder

stop? ​

optional stop?: () => void | Promise<void>

Run when the adapter stops, after the server is closed.

Returns ​

void | Promise<void>

Released under the MIT License.