Last active
April 9, 2021 02:12
-
-
Save vicotrbb/b01a05de033c19a4c954490f9a899eac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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