1 | 'use strict';
|
2 |
|
3 | const config = require('config');
|
4 | const fs = require('fs');
|
5 | const path = require('path');
|
6 | const routePath = `${config.get('nitro.basePath')}project/routes/`;
|
7 | const viewDataPath = `${config.get('nitro.basePath')}project/viewData/`;
|
8 | const routers = [];
|
9 |
|
10 | function 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 |
|
18 | readRoutes(routePath);
|
19 | readRoutes(viewDataPath);
|
20 |
|
21 | module.exports = function (app) {
|
22 | routers.forEach((routedefinition) => {
|
23 | routedefinition(app);
|
24 | });
|
25 | };
|