Skip to content

Commit

Permalink
Merge pull request #9 from adamjosefus/development
Browse files Browse the repository at this point in the history
Update MaskRouter.ts
  • Loading branch information
adamjosefus authored Feb 18, 2022
2 parents 8342ed2 + 04d18a0 commit 2020638
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion routers/MaskRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/


import { Cache } from "https://deno.land/x/allo_caching@v1.0.0/mod.ts";
import { Cache } from "https://deno.land/x/allo_caching@v1.0.2/mod.ts";
import { type IRouter } from "../types/IRouter.ts";
import { Router } from "./Router.ts";
import { type ServeResponseType } from "../types/ServeResponseType.ts";
Expand Down
2 changes: 1 addition & 1 deletion routers/PatternRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/


import { Cache } from "https://deno.land/x/allo_caching@v1.0.0/mod.ts";
import { Cache } from "https://deno.land/x/allo_caching@v1.0.2/mod.ts";
import { ServeResponseType } from "../types/ServeResponseType.ts";
import { type IRouter } from "../types/IRouter.ts";
import { Router } from "./Router.ts";
Expand Down
24 changes: 16 additions & 8 deletions routers/RouterList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { RegExpRouter } from "./RegExpRouter.ts";
import { MaskRouter } from "./MaskRouter.ts";


type AddMethodEntry =
| [mask: string, serveResponse: ServeResponseType]
| [pattern: URLPattern, serveResponse: ServeResponseType]
| [regexp: RegExp, serveResponse: ServeResponseType];


/**
* Class `RouterList` is main object. Contains all routers.
*
Expand Down Expand Up @@ -66,23 +72,25 @@ export class RouterList implements IRouter {
* It will be used as *regexp* for `RegExpRouter`.
*
*/
add(entry: string | URLPattern | RegExp, serveResponse: ServeResponseType): void {
if (typeof entry === "string") {
this.#addMaskRoute(entry, serveResponse);
add(...entry: AddMethodEntry): void {
const [route, serveResponse] = entry;

if (typeof route === "string") {
this.#addMaskRoute(route, serveResponse);
return;
}

if (entry instanceof URLPattern) {
this.#addPatternRoute(entry, serveResponse);
if (route instanceof URLPattern) {
this.#addPatternRoute(route, serveResponse);
return;
}

if (entry instanceof RegExp) {
this.#addRegExpRoute(entry, serveResponse);
if (route instanceof RegExp) {
this.#addRegExpRoute(route, serveResponse);
return;
}

throw new Error("Invalid entry");
throw new Error("Invalid route.");
}


Expand Down

0 comments on commit 2020638

Please sign in to comment.