forked from mansona/express-autoroute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 1.05 KB
/
index.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
var loader = require('./lib/loader');
var path = require('path');
module.exports = function(app, options) {
//is a winston instance is passed as the second argument it will be used for autoroute logging
//otherwise it will use a 'clean' winston instance
if (!options.logger || (!(options.logger.debug && typeof options.logger.debug == 'function'))) {
options.logger = require('winston');
options.logger.debug('using custom logger');
} else {
options.logger.debug('using specified logger')
}
if (!options.routesDir && !options.routeFile) {
options.routesDir = path.join(process.cwd(), "routes");
}
if (options.routesDir) {
options.logger.debug("Loading routes directory", {
dir: options.routesDir
});
loader.loadDirectory(options.routesDir, "", app, options);
} else if (options.routeFile) {
options.logger.debug("Loading route file", {
file: options.routeFile
});
loader.loadFile(options.routeFile, "", app, options);
}
};