diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index 2b267161..60d0648b 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -202,10 +202,11 @@ module.exports = class ApiRouter { app.layergroupAffectedTablesCache = this.layergroupAffectedTablesCache; } - Object.keys(this.serverOptions.routes).forEach(api => { - const routes = this.serverOptions.routes[api]; + Object.values(this.serverOptions.routes).forEach(route => { const apiRouter = router({ mergeParams: true }); - const apiMiddlewares = routes.middlewares || []; + + const apiPaths = route.paths; + const apiMiddlewares = route.middlewares || []; apiMiddlewares.forEach(middleware => apiRouter.use(middleware())); @@ -221,15 +222,13 @@ module.exports = class ApiRouter { apiRouter.use(cors()); apiRouter.use(user()); - this.templateRouter.register(apiRouter, routes.template.paths, routes.template.middlewares); - this.mapRouter.register(apiRouter, routes.map.paths, routes.map.middlewares); + this.templateRouter.register(apiRouter, route.template.paths, route.template.middlewares); + this.mapRouter.register(apiRouter, route.map.paths, route.map.middlewares); apiRouter.use(sendResponse()); apiRouter.use(syntaxError()); apiRouter.use(errorMiddleware()); - const apiPaths = routes.paths; - apiPaths.forEach(path => app.use(path, apiRouter)); }); }