UNPKG

@athenna/http

Version:

The Athenna Http server. Built on top of fastify.

116 lines (115 loc) 3.04 kB
/** * @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 { RouteResourceTypes, TerminatorRouteType, MiddlewareRouteType, InterceptorRouteType } from '#src/types'; import { Route } from '#src/router/Route'; import { Macroable } from '@athenna/common'; export declare class RouteResource extends Macroable { /** * All routes registered in the resource. */ routes: Route[]; /** * The resource name. */ resource: string; /** * The resource controller. */ controller: any; constructor(resource: string, controller: any); /** * Set a validator for the route resource. * * @example * ```ts * Route.resource('/test', 'TestController').validator('auth') * ``` */ validator(validator: MiddlewareRouteType, prepend?: boolean): RouteResource; /** * Set a middleware for the route resource. * * @example * ```ts * Route.resource('/test', 'TestController').middleware('auth') * ``` */ middleware(middleware: MiddlewareRouteType, prepend?: boolean): RouteResource; /** * Set a interceptor for the route resource. * * @example * ```ts * Route.resource('/test', 'TestController').interceptor('response') * ``` */ interceptor(interceptor: InterceptorRouteType, prepend?: boolean): RouteResource; /** * Set a terminator for the route resource. * * @example * ```ts * Route.resource('/test', 'TestController').terminator('response') * ``` */ terminator(terminator: TerminatorRouteType, prepend?: boolean): RouteResource; /** * Register only the methods in the array. * * @example * ```ts * Route.resource('/test', 'TestController').only(['index']) * ``` */ only(names: RouteResourceTypes[]): RouteResource; /** * Register all methods except the methods in the array. * * @example * ```ts * Route.resource('/test', 'TestController').except(['index']) * ``` */ except(names: RouteResourceTypes[]): RouteResource; /** * Set up helmet options for route resource. * *@example * ```ts * Route.helmet({ * dnsPrefetchControl: { allow: true } * }) * ``` */ helmet(options: Omit<import('@fastify/helmet').FastifyHelmetOptions, 'global'>): RouteResource; /** * Set up rate limit options for route resource method. * * @example * ```ts * Route.rateLimit({ * max: 3, * timeWindow: '1 minute' * }) * ``` */ rateLimit(options: import('@fastify/rate-limit').RateLimitOptions): RouteResource; /** * Filter routes by name. */ private filter; /** * Create the route. */ private makeRoute; /** * Create all the routes. */ private buildRoutes; }