UNPKG

@piggly/fastify-chassis

Version:

An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.

91 lines (90 loc) 2.79 kB
import type { FastifyInstance, RawServerBase } from 'fastify'; import { HttpServerInterface, ApiServerInterface, DefaultEnvironment, ApiServerOptions } from '../../types'; /** * @file The API server. * @copyright Piggly Lab 2023 */ export declare abstract class AbstractServer<Server extends RawServerBase, AppEnvironment extends DefaultEnvironment> implements ApiServerInterface<Server, AppEnvironment> { /** * The Fastify application. * * @protected * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ protected _app: FastifyInstance<Server>; /** * The options. * * @protected * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ protected _options: ApiServerOptions<Server, AppEnvironment>; /** * Create a new API server. * * @param options The options. * @public * @constructor * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ constructor(options: ApiServerOptions<Server, AppEnvironment>, app: FastifyInstance<Server>); /** * Bootstrap the API server. * * This method will prepare the environment, the logger, * the plugins and the routes for fastify. * * After that, it will return a new HttpServer instance. * This instance will be used to start the server. * * @public * @async * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ bootstrap(): Promise<HttpServerInterface<Server, AppEnvironment>>; /** * Get the Fastify application. * * @public * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ getApp(): FastifyInstance<Server, import("fastify").RawRequestDefaultExpression<Server>, import("fastify").RawReplyDefaultExpression<Server>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>; /** * Get the global environment. * * @public * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ getEnv(): AppEnvironment; /** * Initialize the API server. * * @protected * @memberof ApiServer * @since 1.0.0 * @author Caique Araujo <caique@piggly.com.br> */ protected init(): Promise<void>; /** * Get the default logger configuration. * * @public * @static * @memberof AbstractServer * @since 3.0.0 * @author Caique Araujo <caique@piggly.com.br> */ protected static defaultLogger(env: string, root_path: string, debug: boolean): Record<string, any>; }