routes.js
1.1 KB
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
/**
* Module dependencies.
*/
var scripts = require('../utils/scripts')
, path = require('path')
, fs = require('fs')
, existsSync = fs.existsSync || path.existsSync; // node <=0.6
/**
* Route drawing phase.
*
* This phase will `require` a routes file, allowing the application to draw its
* routes.
*
* This phase is typically the last phase before instructing the server to
* listen. Any initializers should be run prior to drawing routes, ensuring
* that the application is fully prepared to handle requests.
*
* Examples:
*
* app.phase(bootable.routes('routes.js'));
*
* @param {String|Object} options
* @return {Function}
* @api public
*/
module.exports = function (options) {
if ('string' == typeof options) {
options = { filename: options };
}
options = options || {};
var filename = options.filename || 'routes'
, extensions = options.extensions;
return function routes() {
var script = scripts.resolve(path.resolve(filename), extensions);
if (!existsSync(script)) { return; }
require(script).call(this);
};
};