From ec0df0de60215b2e8d14cf27e5c21bff2e61b85a Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Fri, 12 May 2023 13:55:26 +0200 Subject: [PATCH] change HTTPMethod to enum --- mod.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mod.ts b/mod.ts index 50a59e2..8010199 100644 --- a/mod.ts +++ b/mod.ts @@ -11,7 +11,14 @@ type ListenOptions = { staticLocalDir?: string; staticServePath?: string; }; -type HTTPMethod = "GET" | "POST" | "PUSH" | "DELETE"; + +enum HTTPMethod { + GET = "GET", + POST = "POST", + PUSH = "PUSH", + DELETE = "DELETE", +} + type RouteHandler = ( req: RouteRequest, rep: RouteReply, @@ -267,22 +274,22 @@ export class HTTPServer { } get(path: string, handler: RouteHandler) { - this.add("GET", path, handler); + this.add(HTTPMethod.GET, path, handler); } post(path: string, handler: RouteHandler) { - this.add("POST", path, handler); + this.add(HTTPMethod.POST, path, handler); } push(path: string, handler: RouteHandler) { - this.add("PUSH", path, handler); + this.add(HTTPMethod.PUSH, path, handler); } delete(path: string, handler: RouteHandler) { - this.add("DELETE", path, handler); + this.add(HTTPMethod.DELETE, path, handler); } - add(method: HTTPMethod, path: string, handler: RouteHandler) { + private add(method: HTTPMethod, path: string, handler: RouteHandler) { const route = new Route(path, method, handler); if (this.routes.has(route.routeName)) { console.log(`${route.routeName} already registered!`);