1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var sg = require('./sg');
|
7 | var _ = sg._;
|
8 |
|
9 | var verbose = sg.mkVerbose('sgExRoutes');
|
10 |
|
11 | var routes = {};
|
12 |
|
13 | var 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 |
|
25 | routes.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 |
|
43 | return send(res, 404);
|
44 | }
|
45 |
|
46 |
|
47 | _.each(routes, function(value, name) {
|
48 | exports[name] = value;
|
49 | });
|
50 |
|