1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:59:28 +00:00

Fix bug where multiple route files can't have the same root

This commit is contained in:
2022-02-08 21:49:15 +00:00
parent 3af8bc9454
commit 4731d362a5

10
app.js
View File

@@ -19,11 +19,11 @@ const importJSON = require('./lib/importJSON');
/** /**
* loadRoutes() Loads all of the routes from /routers into a map * loadRoutes() Loads all of the routes from /routers into a map
* *
* @return {Map<String, Object>} Map of all of the routes * @return {Array<Array<String, Object>>} Map of all of the routes
*/ */
function loadRoutes() { function loadRoutes() {
// Load route files // Load route files
const routes = new Map(); const routes = [];
const routeFiles = const routeFiles =
fs.readdirSync(path.join(__dirname, 'routes')) fs.readdirSync(path.join(__dirname, 'routes'))
@@ -31,7 +31,7 @@ function loadRoutes() {
for (const file of routeFiles) { for (const file of routeFiles) {
const route = require(path.join(__dirname, 'routes', file)); const route = require(path.join(__dirname, 'routes', file));
routes.set(route.root, route.router); routes.push([ route.root, route.router ]);
} }
return routes; return routes;
@@ -92,8 +92,8 @@ async function main() {
next(); next();
}); });
for (const [ root, router ] of loadRoutes().entries()) for (const route of loadRoutes())
app.use(root, router); app.use(route[0], route[1]);
// If the request gets to the bottom of the route stack, it doesn't // 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 // have a defined route and therefore a HTTP status code 404 is sent