Skip to content

Commit

Permalink
feat(config): add search path of config file
Browse files Browse the repository at this point in the history
  • Loading branch information
sunYanxl committed Aug 8, 2018
1 parent a5f8819 commit 3ff1e38
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bin/proxy/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const path = require('path');
const plug = require('plug');
const Deferred = plug('util/Deferred');
const defaultValue = plug('default/config.default.js');

const processArgs = plug('util/process.args.js');
const cwd = process.cwd();
const currConfig = path.join(cwd, 'tsw.config.js');
let isFirstLoad = false;
let cache = {
config: null
Expand Down Expand Up @@ -43,8 +45,12 @@ if (isFirstLoad) {
};
})(process.dlopen);
}
if (fs.existsSync(path.join(process.cwd(), 'tsw.config.js'))) {
cache.config = require(path.join(process.cwd(), 'tsw.config.js'));


if (typeof processArgs.config === 'string') {
cache.config = path.join(cwd, processArgs.config);
} else if (fs.existsSync(currConfig)) {
cache.config = require(currConfig);
} else if (fs.existsSync('/etc/tsw.config.js')) {
cache.config = require('/etc/tsw.config.js');
} else if (fs.existsSync('/usr/local/node_modules/config.js')) {
Expand Down

0 comments on commit 3ff1e38

Please sign in to comment.