-
Notifications
You must be signed in to change notification settings - Fork 46
/
serve.js
43 lines (42 loc) · 1.25 KB
/
serve.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
serve = function(path, handler) {
if (Package["iron:router"]){
Package["iron:router"].Router.route(path, function(){
handler(this.request, this.response, this.next);
}, {where: "server"});
} else if (Package["meteorhacks:picker"]){
Package["meteorhacks:picker"].Picker.route(path, function(params, req, res, next){
req.query = params.query;
handler(req, res, next);
});
} else {
WebApp.rawConnectHandlers.use(function(req, res, next){
if (req.path === path) {
handler(req, res, next);
} else {
next();
}
});
}
};
serveDir = function(dir, handler){
//path starts with dir
if (Package["iron:router"]){
Package["iron:router"].Router.route(dir + "/:stuff", function(){
handler(this.request, this.response, this.next);
}, {where: "server"});
} else if (Package["meteorhacks:picker"]){
Package["meteorhacks:picker"].Picker.route(dir + "/:stuff", function(params, req, res, next){
req.query = params.query;
handler(req, res, next);
});
} else {
var regex = new RegExp("^" + dir);
WebApp.rawConnectHandlers.use(function(req, res, next){
if (regex.test(req.path)) {
handler(req, res, next);
} else {
next();
}
});
}
};