Repository navigation
Expand file tree
/
Copy pathcreateRouter.ts
More file actions
65 lines (56 loc) · 1.62 KB
/
Copy pathcreateRouter.ts
File metadata and controls
65 lines (56 loc) · 1.62 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright © 2026 Fells Code, LLC
* Licensed under the Apache License, Version 2.0
* See LICENSE file in the project root for full license information
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Router } from 'express';
import { defineRoute } from './defineRoute.js';
export function createRouter(basePath = '', baseRouter: Router = Router()) {
function withBase(path: string) {
return `${basePath}${path}`;
}
return {
router: baseRouter,
get(path: string, options: Omit<any, 'method' | 'path' | 'handler'>, handler: any) {
defineRoute(baseRouter, {
method: 'get',
path: withBase(path),
...options,
handler,
});
},
post(path: string, options: Omit<any, 'method' | 'path' | 'handler'>, handler: any) {
defineRoute(baseRouter, {
method: 'post',
path: withBase(path),
...options,
handler,
});
},
put(path: string, options: Omit<any, 'method' | 'path' | 'handler'>, handler: any) {
defineRoute(baseRouter, {
method: 'put',
path: withBase(path),
...options,
handler,
});
},
patch(path: string, options: Omit<any, 'method' | 'path' | 'handler'>, handler: any) {
defineRoute(baseRouter, {
method: 'patch',
path: withBase(path),
...options,
handler,
});
},
delete(path: string, options: Omit<any, 'method' | 'path' | 'handler'>, handler: any) {
defineRoute(baseRouter, {
method: 'delete',
path: withBase(path),
...options,
handler,
});
},
};
}