forked from ritch/dpd-express
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (39 loc) · 1.04 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
var util = require('util'),
path = require('path'),
cwd = path.resolve('.'),
Resource = require(path.join(cwd, 'node_modules', 'deployd/lib/resource')),
express = require('express');
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(cwd, 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
};
e.events.init.run({}, domain);
e.app.use(function (req, res) {
res._finished = true;
});
}
fn();
});
};