-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.js
57 lines (53 loc) · 1.57 KB
/
router.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
53
54
55
56
57
'use strict';
var render = require('./render'),
quotes = require('./quotes'),
cache = require('./cache');
/**
* Routed paths. Paths are dictionaries containing a test regex and a
* renderer function.
*
* It's expected that exactly one regex will match a given path. Undefined
* behavior results if this assumption is violated.
*
* the render function is provided with 3 parameters:
* * uri (string): the URI provided by the client (path only)
* * request (Incomming Message): instance of:
* https://nodejs.org/api/http.html#http_http_incomingmessage
* * response (Server Response): instance of
* https://nodejs.org/api/http.html#http_class_http_serverresponse
*
* the render function is expected to handle all aspects of the server
* response itself.
*/
exports.paths = [{
path: /^\/static/,
renderer: render.serveStatic
}, {
path: /^\/(index[.](html?|json|yml))?$/i,
renderer: render.renderIndex
}, {
path: /^\/scripts[.]js$/,
renderer: render.renderScripts
}, {
path: /^\/styles[.]css$/,
renderer: render.renderStyles
}, {
path: /^\/avatar\//,
renderer: quotes.serveAvatar
}];
/**
* Additional paths available in dev mode.
*
* Dev mode is entered by setting the `SOCKDEV` environment variable to a
* truthy value
*/
if (process.env.SOCKDEV) {
exports.paths = exports.paths.concat([{
path: /^\/reset([.]html)?$/i,
renderer: function (uri, request, response) {
cache.buildCache(function () {
render.renderIndex(uri, request, response);
});
}
}]);
}