UNPKG

1.42 kBJavaScriptView Raw
1
2/**
3 *
4 */
5
6var sg = require('./sg');
7var _ = sg._;
8
9var verbose = sg.mkVerbose('sgExRoutes');
10
11var routes = {};
12
13var send = function(res, code, json_) {
14 var json = json_ || {};
15 var body = JSON.stringify(json);
16
17 res.writeHead(code, {
18 'Content-Length': body.length,
19 'Content-Type': 'application/json'
20 });
21
22 res.end(body);
23};
24
25routes.nextMatch = function(req, res, match, err) {
26 if (err) {
27 verbose(0, '---------------------------------------------------------------------------------------------------');
28 verbose(0, '---------------------------------------------------------------------------------------------------');
29 verbose(0, '---------------------------------------------------------------------------------------------------');
30 verbose(0, '---------------------------------------------------------------------------------------------------');
31
32 verbose(0, err);
33
34 verbose(0, '---------------------------------------------------------------------------------------------------');
35 verbose(0, '---------------------------------------------------------------------------------------------------');
36 }
37
38 if ((match = match.next())) {
39 return match.fn(req, res, match);
40 }
41
42 /* otherwise -- no other match; must send error response */
43 return send(res, 404);
44}
45
46
47_.each(routes, function(value, name) {
48 exports[name] = value;
49});
50