Configuration
This section covers the configuration of the main Application
class, we shall also cover the configuration for the most common plugins: HTTP, and WebSocket.
For configuration of the other packages, see their respective API documentation.
Framework Configuration
The Application
class takes a configuration object that allows you to set some options for the framework itself.
typescript
export type IConfig = {
name?: string, // Give your app a name.
logger?: Logger, // Provide your own logger instance (or use the default).
autowire?: boolean, // Enable or disable autowiring of controllers and other parts of the app, we suggest enabling this.
basePath?: string, // Set the base path for the application, this will be different for dev and prod.
// CLI specific options.
enableCli?: boolean, // Enable or disable the CLI interface.
password?: string, // Set a password for the CLI interface.
hostname?: string, // Set the hostname for the CLI interface.
port?: number, // Set the port for the CLI interface.
};
HTTP Configuration
The HttpPlugin
class takes a configuration object that allows you to set some options for the HTTP server.
typescript
export type IConfig = {
port: number, // The port to run the HTTP server on.
host?: string, // The hostname to run the HTTP server on.
ssePath?: string, // The path for Server-Sent Events, defaults to /sse.
// Covers any built-in middlewares you want to enable.
builtInMiddlewares?: {
cors?: boolean, // Enable global CORS support, only use if you understand the implications.
},
};
WebSocket Configuration
The WsPlugin
class takes a configuration object that allows you to set some options for the WebSocket server.
typescript
export type IConfig = {
path?: string | string[], // The path or paths to listen for WebSocket connections on, default is /ws.
keepAlive?: boolean, // Whether to keep the connection alive with pings, default is true.
idleTimeout?: number, // The idle timeout in milliseconds, disabled by default.
backpressureLimit?: number, // The backpressure limit in bytes, default is 1MB (in bytes).
maxPayloadLength?: number, // The maximum payload length in bytes, default is 1MB (in bytes).
closeOnBackpressureLimit?: boolean, // Whether to close the connection when backpressure limit is reached, default is false.
publishToSelf?: boolean, // Whether to publish messages to the sender, default is false.
perMessageDeflate?: unknown, // Relates to Bun's perMessageDeflate option, see Bun docs for more info: https://bun.com/guides/websocket/compression
};