-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanager.js
31 lines (29 loc) · 991 Bytes
/
manager.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
var app;
module.exports = {
getApp: function (callerDirname) {
var contextRoot = callerDirname.substr(__dirname.length + 1);
return {
get: function (path, callback) {
app.get("/" + contextRoot + path, callback);
},
post: function (path, callback) {
app.post("/" + contextRoot + path, callback);
}
}
},
init : function(_app, express){
app = _app
var fs = require('fs');
fs.readdir(__dirname, function(err, files){
if (err) throw err;
files.filter(function(file){
return fs.statSync(__dirname + "/" + file).isDirectory();
}).forEach(function (context) {
//load context
require("./" + context);
//set context root dir as static
app.use("/" + context + "/", express.static(__dirname + "/" + context));
});
});
}
}