From 4731d362a5ce8c731e9b180b0be69cc8a37af72a Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 8 Feb 2022 21:49:15 +0000 Subject: [PATCH] Fix bug where multiple route files can't have the same root --- app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index b86f79c..4dc293e 100644 --- a/app.js +++ b/app.js @@ -19,11 +19,11 @@ const importJSON = require('./lib/importJSON'); /** * loadRoutes() Loads all of the routes from /routers into a map * - * @return {Map} Map of all of the routes + * @return {Array>} Map of all of the routes */ function loadRoutes() { // Load route files - const routes = new Map(); + const routes = []; const routeFiles = fs.readdirSync(path.join(__dirname, 'routes')) @@ -31,7 +31,7 @@ function loadRoutes() { for (const file of routeFiles) { const route = require(path.join(__dirname, 'routes', file)); - routes.set(route.root, route.router); + routes.push([ route.root, route.router ]); } return routes; @@ -92,8 +92,8 @@ async function main() { next(); }); - for (const [ root, router ] of loadRoutes().entries()) - app.use(root, router); + for (const route of loadRoutes()) + app.use(route[0], route[1]); // If the request gets to the bottom of the route stack, it doesn't // have a defined route and therefore a HTTP status code 404 is sent