Files
LupiNex-Connect/.backup/servers/gateway/routers/index.js
T
2026-08-30 15:23:57 +02:00

32 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
! /servers/gateway/routers/index.js Central Gateway Routing Aggregator
? This module dynamically collects and registeres all modular ".router.js" files within the "routers" directory
*/
// % import nodejs packages
const router = require('express').Router();
const path = require('path');
const fs = require('fs');
// % import external dependencies
const rootDir = path.resolve(__dirname, '..', '..', '..');
const { dirs } = require(path.resolve(rootDir, 'configuration', 'mapping.js'));
// % read router files recursively
const routerRoot = path.resolve(dirs.gatewayDir, 'routers');
const routerFiles = fs.readdirSync(routerRoot)
.filter(file => /\.router\.js$/.test(file))
.sort((a, b) => {
if (a === 'root.router.js') return 1;
if (b === 'root.router.js') return -1;
return a.localeCompare(b);
});
// $ configure used routers
routerFiles.forEach(file => {
const routerPath = path.resolve(routerRoot, file);
router.use(require(routerPath));
});
// § export router module
module.exports = router;