fix: change MultiHandler back to Handlers (#1396)

This commit is contained in:
Marvin Hagemeister
2023-07-03 09:57:46 +02:00
committed by GitHub
parent eb53d53ab8
commit 16be99e69b
32 changed files with 135 additions and 66 deletions
+5
View File
@@ -192,6 +192,11 @@ export class ServerContext {
pattern = String(config.routeOverride);
}
let { handler } = module as RouteModule;
if (!handler && "handlers" in module) {
throw new Error(
`Found named export "handlers" in ${self} instead of "handler". Did you mean "handler"?`,
);
}
handler ??= {};
if (
component && typeof handler === "object" && handler.GET === undefined
+5 -5
View File
@@ -103,19 +103,19 @@ export type Handler<T = any, State = Record<string, unknown>> = (
) => Response | Promise<Response>;
// deno-lint-ignore no-explicit-any
export type MultiHandler<T = any, State = Record<string, unknown>> = {
export type Handlers<T = any, State = Record<string, unknown>> = {
[K in router.KnownMethod]?: Handler<T, State>;
};
/**
* @deprecated This type has been deprecated and is replaced with MultiHandler type.
* @deprecated This type was a short-lived alternative to `Handlers`. Please use `Handlers` instead.
*/
export type Handlers<T> = MultiHandler<T>;
export type MultiHandler<T> = Handlers<T>;
export interface RouteModule {
default?: ComponentType<PageProps>;
// deno-lint-ignore no-explicit-any
handler?: Handler<any, any> | MultiHandler<any, any>;
handler?: Handler<any, any> | Handlers<any, any>;
config?: RouteConfig;
}
@@ -125,7 +125,7 @@ export interface Route<Data = any> {
url: string;
name: string;
component?: ComponentType<PageProps<Data>>;
handler: Handler<Data> | MultiHandler<Data>;
handler: Handler<Data> | Handlers<Data>;
csp: boolean;
}