feat: things are happening...
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user