Skip to content

Instantly share code, notes, and snippets.

@vicotrbb
Last active April 9, 2021 02:12
Show Gist options
  • Save vicotrbb/b01a05de033c19a4c954490f9a899eac to your computer and use it in GitHub Desktop.
Save vicotrbb/b01a05de033c19a4c954490f9a899eac to your computer and use it in GitHub Desktop.
/* Estrutura de arquivos
|-- server.js
|-- src
| |-- user
| |--user.controller.js
| |--user.route.js
| |-- product
| |--product.controller.js
| |--product.route.js
| |-- order
| |--order.controller.js
| |--order.route.js
| |-- index.route.js
*/
const _ = require('lodash');
const fs = require('fs');
const excluded = ['index.route.js'];
function loadAllRoutes(app) {
fs.readdir(__dirname, (err, files) => {
files.forEach((folder) => {
if (!_.includes(excluded, folder)) {
fs.readdirSync(`${__dirname}/${folder}`).forEach((file) => {
if (file.includes('route')) {
app.use(require(`./${folder}/${file}`).routePath, require(`./${folder}/${file}`).router);
}
});
}
});
});
}
module.exports = loadAllRoutes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment