feat(compression): Improve compression implementation (buffering and threshold), add Deno brotli support, add compression tests and dynamic route API
This commit is contained in:
@@ -13,6 +13,7 @@ export class ControllerRegistry {
|
||||
private static controllers: Map<Function, IControllerMetadata> = new Map();
|
||||
private static instances: Map<Function, any> = new Map();
|
||||
private static compiledRoutes: ICompiledRoute[] = [];
|
||||
private static dynamicRoutes: ICompiledRoute[] = [];
|
||||
private static routesCompiled = false;
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,29 @@ export class ControllerRegistry {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dynamic route without needing a controller class
|
||||
*/
|
||||
static addRoute(
|
||||
path: string,
|
||||
method: THttpMethod,
|
||||
handler: (ctx: IRequestContext) => Promise<Response | any>
|
||||
): void {
|
||||
const { regex, paramNames } = this.pathToRegex(path);
|
||||
|
||||
this.dynamicRoutes.push({
|
||||
pattern: path,
|
||||
regex,
|
||||
paramNames,
|
||||
method,
|
||||
handler: async (ctx: IRequestContext) => handler(ctx),
|
||||
interceptors: [],
|
||||
compression: undefined,
|
||||
});
|
||||
|
||||
this.routesCompiled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all routes for fast matching
|
||||
*/
|
||||
@@ -107,6 +131,9 @@ export class ControllerRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
// Add dynamic routes
|
||||
this.compiledRoutes.push(...this.dynamicRoutes);
|
||||
|
||||
// Sort routes by specificity (more specific paths first)
|
||||
this.compiledRoutes.sort((a, b) => {
|
||||
// Routes without wildcards come first
|
||||
@@ -194,6 +221,7 @@ export class ControllerRegistry {
|
||||
this.controllers.clear();
|
||||
this.instances.clear();
|
||||
this.compiledRoutes = [];
|
||||
this.dynamicRoutes = [];
|
||||
this.routesCompiled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user