@athenna/http
Version:
The Athenna Http server. Built on top of fastify.
140 lines (139 loc) • 4.41 kB
TypeScript
/**
* @athenna/http
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type { InjectOptions, FastifyInstance, PrintRoutesOptions, FastifyListenOptions, FastifyServerOptions, LightMyRequestChain, LightMyRequestResponse } from 'fastify';
import type { RouteJson, ErrorHandler, RequestHandler, InterceptHandler, TerminateHandler, SwaggerDocument } from '#src/types';
import type { AddressInfo } from 'node:net';
import type { FastifyVite } from '@athenna/vite';
import { Macroable } from '@athenna/common';
export declare class ServerImpl extends Macroable {
/**
* Holds the fastify server instance.
*/
fastify: FastifyInstance;
/**
* Set if the Http server is listening for new requests.
*/
isListening: boolean;
constructor(options?: FastifyServerOptions);
/**
* Get the representation of the internal radix tree used by the
* router.
*/
getRoutes(options?: PrintRoutesOptions): string;
/**
* Get the address info of the server. This method will return the
* port used to listen the server, the family (IPv4, IPv6) and the
* server address (127.0.0.1).
*/
getAddressInfo(): AddressInfo;
/**
* Get the port where the server is running.
*/
getPort(): number;
/**
* Get the host where the server is running.
*/
getHost(): string;
/**
* Get the fastify version that is running the server.
*/
getFastifyVersion(): string;
getSwagger(): Promise<SwaggerDocument>;
getSwagger(options: {
yaml: true;
}): Promise<string>;
getSwagger(options: {
yaml: false;
}): Promise<SwaggerDocument>;
/**
* Set the error handler to handle errors that happens inside the server.
*/
setErrorHandler(handler: ErrorHandler): ServerImpl;
/**
* Register a plugin inside the fastify server.
*/
plugin(plugin: any, options?: any): Promise<void>;
/**
* Create a middleware that will be executed before the request gets
* inside the route handler.
*/
middleware(handler: RequestHandler): ServerImpl;
/**
* Create an interceptor that will be executed before the response
* is returned. At this point you can still make modifications in the
* response.
*/
intercept(handler: InterceptHandler): ServerImpl;
/**
* Create and terminator that will be executed after the response
* is returned. At this point you cannot make modifications in the
* response.
*/
terminate(handler: TerminateHandler): ServerImpl;
/**
* Return a request handler to make internal requests to the Http server.
*/
request(): LightMyRequestChain;
/**
* Return a request handler to make internal requests to the Http server.
*/
request(options: InjectOptions): Promise<LightMyRequestResponse>;
/**
* Make the server start listening for requests.
*/
listen(options: FastifyListenOptions): Promise<any>;
/**
* Return the FastifyVite instance if it exists.
*/
getVitePlugin(): FastifyVite;
/**
* Return ViteDevServer instance if it exists.
*/
getViteDevServer(): import("vite").ViteDevServer;
/**
* Start vite server.
*/
viteReady(): Promise<void>;
/**
* Close the server,
*/
close(): Promise<void>;
/**
* Add a new route to the http server.
*/
route(options: RouteJson): void;
/**
* Add a new GET route to the http server.
*/
get(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new HEAD route to the http server.
*/
head(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new POST route to the http server.
*/
post(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new PUT route to the http server.
*/
put(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new PATCH route to the http server.
*/
patch(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new DELETE route to the http server.
*/
delete(options: Omit<RouteJson, 'methods'>): void;
/**
* Add a new OPTIONS route to the http server.
*/
options(options: Omit<RouteJson, 'methods'>): void;
}