Skip to content

Commit 1fdb419

Browse files
committed
Support define own config file
1 parent 4bd69f3 commit 1fdb419

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

core.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
// Import Packages
44
const winston = require('winston')
55
const nconf = require('nconf')
6+
const path = require('path')
67
const colors = require('colors/safe')
78
const Koa = require('koa') // Koa v2
89
// const mail = require('./src/mail')
910

11+
// Read Command
12+
let configFile
13+
const paramsArray = process.argv.slice(2)
14+
if (paramsArray.length > 1) {
15+
// exist params
16+
if (paramsArray[0] === '--config_file') {
17+
configFile = path.join('./', paramsArray[1])
18+
}
19+
}
20+
1021
// PreStart
1122
const preStart = require('./src/prestart')
12-
preStart.load()
23+
preStart.load(configFile)
1324

1425
// Use blubird promise
1526
global.Promise = require('bluebird')

src/prestart.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ function printCopyright () {
5858
}
5959

6060
module.exports = {
61-
load: () => {
61+
load: (config_file) => {
62+
if (!config_file) {
63+
config_file = path.join(__dirname, '../', 'config.json')
64+
}
6265
setupWinston()
63-
loadConfig(path.join(__dirname, '../', 'config.json'))
66+
loadConfig(config_file)
6467
printCopyright()
6568
}
6669
}

0 commit comments

Comments
 (0)