UNPKG

burger-api

Version:

<p align="center"> <img src="https://github.com/user-attachments/assets/0d9b376e-1d89-479a-aa7f-e7ee3c6b2342" alt="BurgerAPI logo"/> </p>

78 lines (77 loc) 2.38 kB
import type { ServerOptions } from '@burgerTypes'; export declare class Burger { private options; /** * The server instance */ private server; /** * The API router instance */ private apiRouter?; /** * The page router instance */ private pageRouter?; /** * The global middleware */ private globalMiddleware; /** * The OpenAPI document */ private openApiDoc; /** * The routes object */ private routes; /** * Pre-computed responses for reuse */ private readonly METHOD_NOT_ALLOWED; /** * The not found response */ private readonly NOT_FOUND; /** * The OpenAPI error response */ private readonly OPENAPI_ERROR; /** * Constructor for the Burger class. * @param options - The options for the server and router. * The options object should contain the following properties: * - port: The port number to listen on. * - apiDir: The directory path to load API routes from. * - pageDir: The directory path to load page routes from. * - middleware: An array of global middleware functions. */ constructor(options: ServerOptions); /** * Process the page routes and add them to the routes object * @returns A promise that resolves to a boolean */ private processPageRoutes; /** * Process the API routes and add them to the routes object * @returns A promise that resolves to a boolean */ private processApiRoutes; /** * Process the middleware and handler * @param request - The request object * @param middlewares - The middleware array * @param handler - The handler function * @returns A promise that resolves to a response */ private processMiddleware; /** * Starts the server and begins listening for incoming requests. * @param port - The port number to listen on. Defaults to `4000`. * @param cb - An optional cb function to be executed when the server is listening. * @returns A Promise that resolves when the server has started listening. */ serve(port?: number, cb?: () => void): Promise<void>; } export { setDir } from './utils/index.js'; export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, } from '@burgerTypes';