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.`); }