-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
51 lines (44 loc) · 1.24 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Method } from "./method.ts";
import { Handler } from "./handler.ts";
import { Route } from "./route.ts";
import { Router } from "./router.ts";
export {
Route,
};
export function createRouter() {
return new Router();
}
export function addRequestRoute(
method: Method,
path: string,
handler: Handler,
) {
return new Route(method, path, handler);
}
export const addGetRoute = addRequestRoute.bind(null, Method.Get);
export const addPostRoute = addRequestRoute.bind(null, Method.Post);
export const addPatchRoute = addRequestRoute.bind(null, Method.Patch);
export const addDeleteRoute = addRequestRoute.bind(null, Method.Delete);
export function routesBind(routes: Route[]) {
function pushRequestRoute(
method: Method,
path: string,
handler: Handler,
) {
routes.push(new Route(method, path, handler));
}
return {
addRequestRoute: pushRequestRoute,
addGetRoute: pushRequestRoute.bind(null, Method.Get),
addPostRoute: pushRequestRoute.bind(null, Method.Post),
addPatchRoute: pushRequestRoute.bind(null, Method.Patch),
addDeleteRoute: pushRequestRoute.bind(null, Method.Delete),
};
}
export function createRoutes() {
const routes: Route[] = [];
return {
routes,
...routesBind(routes),
};
}