Basic Structure
baseUrl
Specifies the full URL where the server is externally accessible. Type:string (optional)
Default: http://{listen.host}:{listen.port}
listen
Configures the port and host the server listens on. Type: (optional)port
The port number the server listens on. Type:number
host
The host address the server binds to. Type:string (optional)
Default: "localhost"
fastify
Configures Fastify server options. Type:Omit<FastifyServerOptions, "logger"> (optional)
Logging is configured separately through Sonamu’s
logging settings.plugins
Enables and configures Fastify plugins.formbody
Parsesapplication/x-www-form-urlencoded request bodies.
Type: boolean | FastifyFormbodyOptions (optional)
qs
Parses query strings. Supports nested objects and arrays. Type:boolean | QsPluginOptions (optional)
multipart
Handles file uploads (multipart/form-data).
Type: boolean | FastifyMultipartOptions (optional)
static
Serves static files. Type:boolean | FastifyStaticOptions (optional)
/api/public/images/logo.png → public/images/logo.png file
session
Enables session management. Type:boolean | SecureSessionPluginOptions (optional)
compress
Compresses responses. See separate documentation for details. Type:boolean | FastifyCompressOptions (optional)
cors
Configures CORS (Cross-Origin Resource Sharing). Type:boolean | FastifyCorsOptions (optional)
sse
Supports Server-Sent Events. Type:boolean | SsePluginOptions (optional)
custom
Registers custom Fastify plugins. Type:(server: FastifyInstance) => void (optional)
apiConfig
Configures API behavior.contextProvider
A function that creates Context for each API call. Type:(defaultContext, request) => Context
guardHandler
A function called when Guard decorators execute. Type:(guard, request, api) => void | Promise<void>
cacheControlHandler
A function that sets Cache-Control headers. Type:(req) => string | undefined
lifecycle
Registers hooks for server lifecycle events.onStart
Executes when the server starts. Type:(server: FastifyInstance) => void | Promise<void>
onShutdown
Executes when the server shuts down (graceful shutdown). Type:(server: FastifyInstance) => void | Promise<void>
onError
Executes when an unhandled error occurs. Type:(error, request, reply) => void | Promise<void>