From b99923cd9078d2c478856acec9b17b29e9c4c02f Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sat, 30 May 2020 14:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=EF=BC=9A=E6=97=A0=E8=AE=BA?= =?UTF-8?q?=E6=9C=89=E6=B2=A1=E6=9C=89=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E9=83=BD=E8=A6=81Object.assign(=E6=9C=80=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E9=85=8D=E7=BD=AE=EF=BC=8C=E7=94=A8=E6=88=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfigBasic.js | 7 +++++++ server.js | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 ConfigBasic.js diff --git a/ConfigBasic.js b/ConfigBasic.js new file mode 100644 index 0000000..a09cc85 --- /dev/null +++ b/ConfigBasic.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = { // 全大写字母的,代表系统常量,不要在 userConfig 或命令行参数里覆盖。小写驼峰的,是用户可以覆盖的。 + commanderOptions: [ // 命令行里可以接受的参数。将传给 config.js 里的 commander。每个参数的定义格式是 [参数名,参数键,描述],后两者用于传给commander,取值后覆盖掉Config里的同名变量。 + ['port', '-p, --port ', 'web server port'] + ] +} diff --git a/server.js b/server.js index bdd0501..e873d15 100644 --- a/server.js +++ b/server.js @@ -1,9 +1,8 @@ const fs = require('fs') const path = require('path') -const Config = require('so.base/Config.js') -if (!Config || Object.keys(Config).length===0) { - Config = { // 默认配置,如果用户什么也没有提供 +const Config = Object.assign({ + // 最基础的必须的默认配置,如果用户什么也没有提供 protocol: 'http', host: 'localhost', 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: ['']} ], */ - } -} + }, + require('so.base/Config.js') +) if (typeof(Config.ssl)==='string') { Config.ssl = eval(`(${Config.ssl})`) }