Clean up how route handlers are called

This commit is contained in:
Michael Wolf
2025-03-07 21:22:31 -06:00
parent 6ed81e871f
commit ecdbedc135
4 changed files with 64 additions and 27 deletions

View File

@@ -18,13 +18,13 @@ const methodParser = z.union([
export type Method = z.infer<typeof methodParser>;
const massageMethod = (input: string): Method => {
const r = methodParser.parse(input.toUpperCase())
const r = methodParser.parse(input.toUpperCase());
return r;
};
export type DenoRequest = globalThis.Request;
export type DenoResponse=globalThis.Response;
export type DenoResponse = globalThis.Response;
export type UserRequest = {};
export type Request = {
pattern: string;
@@ -33,10 +33,14 @@ export type Request = {
parameters: object;
denoRequest: globalThis.Request;
};
export type InternalHandler = (req: DenoRequest) => Promise<Response>;
export type Handler = (req: Request) => Promise<Response> | Response;
export type ProcessedRoute = {
pattern: URLPattern;
method: Method;
handler: Handler;
handler: InternalHandler;
};
export type Response = {
@@ -45,8 +49,6 @@ export type Response = {
result: string;
};
export type Handler = (req: Request) => Promise<Response>;
export type Route = {
path: string;
methods: Method[];