This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
SA3/hw6/Claudio_Maggioni/routes/routers.js
2019-10-28 15:01:43 +01:00

35 lines
845 B
JavaScript

/** @module routes/routers
* Exposes all routers
*/
'use strict';
const fs = require('fs');
const dirEntries = fs.readdirSync(__dirname);
const base = __dirname + '/';
const routers = {};
try{
dirEntries.forEach(function(dirEntry){
const stats = fs.statSync(base + dirEntry);
//try to load router of dir
if(stats.isDirectory()){
try{
const router = require(base + dirEntry + '/router');
//add router to our list of routers;
routers[dirEntry] = router;
}catch(err){
console.log('Could not get router for ' + dirEntry);
console.log(err.toString() + err.stack);
}
}
});
}catch(err){
console.log('Error while loading routers');
console.log(err.stack);
//We don't know what happened, export empty object
routers = {}
}finally{
module.exports = routers;
}