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
|
import * as routes from './routes/index.js';
function logHttpEntry(method, route, exampleBody, description) {
if (description) console.log('%', '#', description);
console.log('%', method, '{{baseUrl}}' + route, 'HTTP/1.1');
if (exampleBody) {
console.log('%', 'Content-Type: application/json');
console.log('% ');
console.log('%', JSON.stringify(exampleBody, null, 4));
console.log('% ');
}
console.log('% ');
console.log('%', '###');
}
export function registerRoutes(app) {
// http file header:
console.log('%', '');
let routeCount = 0;
Object.keys(routes).forEach(routeName => {
/**
* @type {RouteDescription}
*/
const route = routes[routeName];
Object.keys(route.methods).forEach(routeMethodName => {
/**
* @type {RouteMethod}
*/
const routeMethod = route.methods[routeMethodName];
console.log(
'Registering',
routeMethodName.toUpperCase(),
route.path
);
logHttpEntry(
routeMethodName.toUpperCase(),
route.path,
routeMethod.exampleBody
);
app[routeMethodName](route.path, [
...routeMethod.middlewares,
routeMethod.method
]);
routeCount++;
});
});
console.log(`Registered ${routeCount} routes.`);
}
|