UNPKG

629 BJavaScriptView Raw
1'use strict';
2
3const config = require('config');
4const fs = require('fs');
5const path = require('path');
6const routePath = `${config.get('nitro.basePath')}project/routes/`;
7const viewDataPath = `${config.get('nitro.basePath')}project/viewData/`;
8const routers = [];
9
10function readRoutes(routes) {
11 fs.readdirSync(routes).forEach((el) => {
12 if (path.extname(el) === '.js') {
13 routers.push(require(routes + path.basename(el, '.js')));
14 }
15 });
16}
17
18readRoutes(routePath);
19readRoutes(viewDataPath);
20
21module.exports = function (app) {
22 routers.forEach((routedefinition) => {
23 routedefinition(app);
24 });
25};