import type { FastifyCorsOptions } from '@fastify/cors'; import type { FastifyMultipartOptions } from '@fastify/multipart'; import type { ModuleMetadata } from '@navios/core'; import type { FastifyInstance, FastifyListenOptions } from 'fastify'; import { Container } from '@navios/core'; import type { FastifyApplicationOptions, FastifyApplicationServiceInterface } from '../interfaces/application.interface.mjs'; /** * Fastify HTTP adapter service implementation for Navios. * * This service provides the core HTTP server functionality for Navios applications * running on the Fastify runtime. It handles server initialization, route registration, * request handling, CORS configuration, multipart support, and server lifecycle management. * * @example * ```ts * const app = await NaviosFactory.create(AppModule, { * adapter: defineFastifyEnvironment(), * }) * * app.configure({ * logger: true, * trustProxy: true, * }) * * app.enableCors({ origin: true }) * app.enableMultipart({ limits: { fileSize: 10 * 1024 * 1024 } }) * * await app.init() * await app.listen({ port: 3000, host: '0.0.0.0' }) * ``` * * @implements {FastifyApplicationServiceInterface} */ export declare class FastifyApplicationService implements FastifyApplicationServiceInterface { private logger; protected container: Container; private errorProducer; private validatorCompiler; private server; private controllerAdapter; private globalPrefix; private corsOptions; private multipartOptions; private configureOptions; /** * Sets up the Fastify HTTP adapter with the provided options. * * This method is called during application initialization. * It creates the Fastify instance, configures logging, and prepares the server * for route registration. * * @param options - Fastify server configuration options including logger settings, * trust proxy configuration, and other Fastify-specific options. * * @example * ```ts * app.configure({ * logger: true, * trustProxy: true, * disableRequestLogging: false, * }) * await app.init() * ``` */ setupAdapter(options: FastifyApplicationOptions): Promise; /** * Initializes the Fastify server instance and configures plugins. * * This method is called automatically during server setup. It configures * error handlers, not found handlers, schema validators, and registers * the server instance in the dependency injection container. */ initServer(): Promise; /** * Waits for the Fastify server to be ready. * * This method ensures all plugins are registered and the server is ready * to accept connections before starting to listen. */ ready(): Promise; /** * Sets a global prefix for all routes. * * This prefix will be prepended to all registered route paths. Useful for * API versioning or organizing routes under a common path. * * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1'). * Should start with a forward slash. * * @example * ```ts * app.setGlobalPrefix('/api/v1') * // All routes will be prefixed with /api/v1 * ``` */ setGlobalPrefix(prefix: string): void; /** * Gets the current global prefix for all routes. * * @returns The global prefix string, or empty string if no prefix is set. * * @example * ```ts * app.setGlobalPrefix('/api/v1') * console.log(app.getGlobalPrefix()) // '/api/v1' * ``` */ getGlobalPrefix(): string; /** * Gets the underlying Fastify server instance. * * This allows direct access to the Fastify instance for advanced use cases, * such as registering custom plugins, hooks, or decorators. * * @returns The Fastify server instance. * @throws {Error} If the server has not been initialized yet. * * @example * ```ts * const fastify = app.getServer() * await fastify.register(require('@fastify/static'), { * root: path.join(__dirname, 'public'), * }) * ``` */ getServer(): FastifyInstance; onModulesInit(modules: Map): Promise; /** * Configures Fastify instance with error handlers, validators, and serializers. * * Sets up: * - Global error handler for HttpException and other errors * - Not found handler for unmatched routes * - Zod-based validator and serializer compilers * * @private */ configureFastifyInstance(): void; /** * Configures and registers Fastify plugins (CORS, multipart, etc.). * * This method registers plugins that were configured via `enableCors()` * and `enableMultipart()` methods. * * @private */ configurePlugins(): Promise; /** * Configures multipart form data support. * * @param options - Multipart configuration options or `true` for defaults. * @private */ configureMultipart(options: FastifyMultipartOptions | true): Promise; /** * Registers the Fastify instance in the dependency injection container. * * Makes the server instance available for injection via `FastifyServerToken`. * * @private */ registerFastifyInstance(): void; /** * Enables CORS (Cross-Origin Resource Sharing) support. * * Configures CORS headers for all routes. The options are applied when * the server is initialized. * * @param options - CORS configuration options from `@fastify/cors`. * * @example * ```ts * app.enableCors({ * origin: true, // Allow all origins * methods: ['GET', 'POST', 'PUT', 'DELETE'], * credentials: true, * }) * ``` * * @see {@link https://github.com/fastify/fastify-cors} Fastify CORS plugin documentation */ enableCors(options: FastifyCorsOptions): void; /** * Enables multipart form data support for file uploads. * * Configures multipart handling for all routes. The options are applied when * the server is initialized. * * @param options - Multipart configuration options from `@fastify/multipart`. * * @example * ```ts * app.enableMultipart({ * limits: { * fileSize: 10 * 1024 * 1024, // 10MB * files: 5, // Max 5 files * }, * }) * ``` * * @see {@link https://github.com/fastify/fastify-multipart} Fastify Multipart plugin documentation */ enableMultipart(options: FastifyMultipartOptions): void; /** * Starts the Fastify HTTP server and begins listening for incoming requests. * * This method starts the server with the configured routes and options. * The server will handle all registered routes and return 404 for unmatched requests. * * @param options - Server listen options including port and host. * @returns A promise that resolves to the server address string. * * @example * ```ts * const address = await app.listen({ * port: 3000, * host: '0.0.0.0', * }) * console.log(`Server listening on ${address}`) * ``` */ listen(options: FastifyListenOptions): Promise; /** * Configures the adapter with additional options before initialization. * * Options set via configure() are merged with options passed to * setupAdapter(), with configure() options taking precedence. * Must be called before init(). * * @param options - Partial Fastify server configuration options * * @example * ```ts * app.configure({ trustProxy: true, logger: true }) * await app.init() * ``` */ configure(options: Partial): void; /** * Gracefully shuts down the Fastify server. * * This method closes all connections and cleans up resources. Should be called * during application shutdown to ensure proper cleanup. * * @example * ```ts * process.on('SIGTERM', async () => { * await app.dispose() * process.exit(0) * }) * ``` */ dispose(): Promise; } //# sourceMappingURL=application.service.d.mts.map