纠正:无论有没有用户配置,都要Object.assign(最基础配置,用户配置)
This commit is contained in:
parent
c432743461
commit
b99923cd90
7
ConfigBasic.js
Normal file
7
ConfigBasic.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = { // 全大写字母的,代表系统常量,不要在 userConfig 或命令行参数里覆盖。小写驼峰的,是用户可以覆盖的。
|
||||||
|
commanderOptions: [ // 命令行里可以接受的参数。将传给 config.js 里的 commander。每个参数的定义格式是 [参数名,参数键,描述],后两者用于传给commander,取值后覆盖掉Config里的同名变量。
|
||||||
|
['port', '-p, --port <number>', 'web server port']
|
||||||
|
]
|
||||||
|
}
|
10
server.js
10
server.js
@ -1,9 +1,8 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const Config = require('so.base/Config.js')
|
const Config = Object.assign({
|
||||||
if (!Config || Object.keys(Config).length===0) {
|
// 最基础的必须的默认配置,如果用户什么也没有提供
|
||||||
Config = { // 默认配置,如果用户什么也没有提供
|
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
from: './dist', // local path to serve as webroot
|
from: './dist', // local path to serve as webroot
|
||||||
@ -13,8 +12,9 @@ if (!Config || Object.keys(Config).length===0) {
|
|||||||
{ webroot: 'dist', webindex: 'index.html', domainList: ['']}
|
{ webroot: 'dist', webindex: 'index.html', domainList: ['']}
|
||||||
],
|
],
|
||||||
*/
|
*/
|
||||||
}
|
},
|
||||||
}
|
require('so.base/Config.js')
|
||||||
|
)
|
||||||
if (typeof(Config.ssl)==='string') {
|
if (typeof(Config.ssl)==='string') {
|
||||||
Config.ssl = eval(`(${Config.ssl})`)
|
Config.ssl = eval(`(${Config.ssl})`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user