-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.js
66 lines (41 loc) · 1.11 KB
/
test4.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// var dirw = require('dirw');
// dirw.walk('./routes', 0, handleFile);
const router = require('moa-router')()
router.forceRegister = true
var walk = require('walk'),
fs = require('fs'),
walker;
// module.exports =
function a(){
walker = walk.walk("./routes", {});
walker.on("file", function (root, fileStats, next) {
var path = root + '/' + fileStats.name;
if (/js$/.test(path)) {
console.log(path)
var prefix = path.replace('./routes', '').replace('.js', '')
console.log(prefix)
var _router = require(path)
// users.forceRegister = true
_router.prefix = prefix
router.meta = _router.meta
next();
}
});
walker.on("errors", function (root, nodeStatsArray, next) {
next();
});
return new Promise(function (resolve, reject) {
walker.on("end", function () {
console.log("all done");
require('log-n')(router.meta)
resolve(router.routes())
});
})
}
const http = require('http')
const Koa = require('koa')
const app = new Koa()
a().then(function(r){
app.use(router.routes())
})
app.listen(3000)