-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
31 lines (24 loc) · 1.03 KB
/
index.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 anotejs = require('annoteJS'),
path = require('path'),
util = require('util'),
fs = require('fs');
anotejs.registerAnnotations(path.resolve(__dirname, './annotations'));
var anote = anotejs.get();
var controllerHandler = anote.requireWithAnnotations(path.resolve(__dirname, './lib/controller_handler')).get();
function ExpressController(){}
ExpressController.prototype.handle = function(request, response, next) {
return controllerHandler.run(request, response, next);
};
ExpressController.prototype.setControllerRoutes = function(loadPath) {
var anote = anotejs.get();
var realPath = path.resolve(process.cwd(), loadPath);
var stats = fs.statSync(realPath);
if(!fs.existsSync(realPath) || !stats.isDirectory()) {
throw new Exception(util.format("%s location does not exist or is not a directory", realPath));
}
var files = fs.readdirSync(realPath);
files.forEach(function(val) {
anote.requireWithAnnotations(path.resolve(realPath, val));
})
}
module.exports = ExpressController;