-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
53 lines (41 loc) · 1.12 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var util = require('util')
, Resource = require('deployd/lib/resource')
, express = require('express')
, path = require('path');
function Express(name, options) {
Resource.apply(this, arguments);
var app = this.app = express()
, exp = this;
// handle all routes
this.path = '/';
app.set('views', path.join(path.resolve('.'), options.configPath, 'views'));
}
Express.events = ['init'];
util.inherits(Express, Resource);
module.exports = Express;
Express.prototype.handle = function (ctx, next) {
ctx.req.dpd = ctx.dpd;
ctx.req.me = ctx.session && ctx.session.user;
this.app.call(this.server, ctx.req, ctx.res);
if(ctx.res._finished) {
next();
}
}
Express.prototype.load = function (fn) {
var e = this;
Resource.prototype.load.call(this, function () {
if(e.events && e.events.init) {
var domain = {
app: e.app
, require: function () {
return require.apply(module, arguments);
}
}
e.events.init.run({}, domain);
e.app.use(function (req, res) {
res._finished = true;
});
}
fn();
});
}