forked from assets-tokenization/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
46 lines (31 loc) · 1.17 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const auth_mw = require('./controllers/auth/auth_ver')['authenticateToken'];
var normalizedPath = require("path").join(__dirname, "routes");
const routes = [];
require("fs").readdirSync(normalizedPath).forEach(route=>{
routes.push(...require("./routes/" + route) );
});
module.exports = function(app){
const prefix = "/v1/";
const excludes_pref = [
];
for(let route of routes) {
if(typeof route.controller !== 'function') {
console.log(`route not has function ${JSON.stringify(route)}`);
continue;
}
const url = !excludes_pref.includes(route.url) ? prefix+route.url : "/"+route.url;
if(route.type && route.type == 'POST') {
app.post(url, auth_mw(route.auth), route.controller );
continue;
}
if(route.type && route.type == 'PUT') {
app.put(url, auth_mw(route.auth), route.controller );
continue;
}
if(route.type && route.type == 'DELETE') {
app.delete(url, auth_mw(route.auth), route.controller );
continue;
}
app.get(url, auth_mw(route.auth), route.controller);
}
};