legendaryjs
Version:
LegendaryJS – The ultimate backend framework for speed, power, and simplicity.
21 lines (17 loc) • 672 B
JavaScript
const fs = require('fs');
const path = require('path');
function loadRoutes(app) {
const routesPath = path.join(process.cwd(), 'routes/api.v1.json');
if (!fs.existsSync(routesPath)) return;
const { routes = [] } = JSON.parse(fs.readFileSync(routesPath));
routes.forEach(({ method = 'get', path, handlerPath }) => {
try {
const handler = require(path.join(process.cwd(), handlerPath));
app[method](path, handler);
console.log(`✅ Loaded route: [${method.toUpperCase()}] ${path}`);
} catch (err) {
console.error(`❌ Failed loading route ${path}:`, err.message);
}
});
}
module.exports = { loadRoutes };