edge-master
Version:
A Micro Framework for Edges
45 lines (44 loc) • 1.65 kB
TypeScript
/// <reference types="@cloudflare/workers-types" />
import { IRouteHandler } from './types/route';
import { RequestHandlerArgs, IMatcher } from './types/base';
import { IInterceptor } from './types/interceptor';
/**
* EdgeController is a class for managing routes and interceptors in Cloudflare Workers.
*/
export declare class EdgeController {
private _reqInterceptors;
private _hasReqInterceptor;
private _resInterceptors;
private _hasResInterceptor;
private _routes;
constructor();
/**
* Intercepts incoming requests, applies request interceptors, and returns the modified request.
*/
private interceptRequest;
/**
* Intercepts outgoing responses, applies response interceptors, and returns the modified response.
*/
private interceptResponse;
/**
* Handles incoming requests by matching routes and executing the appropriate route handler.
* If no route matches, it falls back to fetching the original request.
*/
private handleRoutes;
/**
* Adds a new route to the router.
* @param matcher The route matcher function.
* @param routeHandler The route handler to execute when the route matches.
*/
addRoute(matcher: IMatcher, routeHandler: IRouteHandler): EdgeController;
/**
* Adds an interceptor to the router.
* @param interceptor The interceptor to add.
*/
addInterceptor(interceptor: IInterceptor): EdgeController;
/**
* Handles an incoming request and returns the response.
* @param reqCtx The request context.
*/
handleRequest(reqCtx: RequestHandlerArgs): Promise<Response>;
}