feat: things are happening...

This commit is contained in:
Daniel Ledda
2022-07-10 23:07:51 +02:00
parent ba68f953f0
commit fb9f78caf7
22 changed files with 448 additions and 207 deletions

View File

@@ -1,22 +1,25 @@
import Http = Deno.errors.Http;
import {JSONObject} from "./JSON.ts";
export type HttpMethod = "POST" | "GET" | "PUT" | "DELETE";
export type RouteDefinition = {
pattern: RegExp;
method: HttpMethod;
method?: HttpMethod;
};
export default class StoccaTreRequest {
constructor(
public method: HttpMethod,
public route: string,
public body: string | null,
public body: JSONObject | null,
) {}
match(route: RouteDefinition): RegExpExecArray | null {
match(route: RouteDefinition): RegExpExecArray | false {
const patternResult = route.pattern.exec(this.route);
if (route.method !== this.method) {
return null;
if (route.method && route.method !== this.method) {
return false;
}
return patternResult;
return patternResult ?? false;
}
}