From 5cbd2831d14168c645fa3164f5b8b1724be0ba02 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 18 Apr 2022 14:49:35 +0000 Subject: [PATCH] Added priority system for route loading --- app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 5b6935f..733cc27 100644 --- a/app.js +++ b/app.js @@ -30,10 +30,18 @@ function loadRoutes() { for (const file of routeFiles) { const route = require(path.join(__dirname, 'routes', file)); - routes.push([ route.root, route.router ]); + routes.push([ route.root, route.router, route.priority, file ]); } - return routes; + return routes.sort((a, b) => { + if (a[2] > b[2] || b[2] == null) + return 1; + + if (a[2] < b[2] || a[2] == null) + return -1; + + return 0; + }); } async function main() {