From c3fc3e2c889733d0d17fc734cc5bb60f34a9bf74 Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Fri, 25 Oct 2019 10:37:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20dist=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BD=9C=20webroot=20=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 4e27a36..46b369e 100644 --- a/server.js +++ b/server.js @@ -39,6 +39,7 @@ try { .option('-H, --host ', `Host ip or domain name. Default to ${Config.host}`) .option('-P, --protocol ', `Web server protocol http|https|httpall|http2https. Default to ${Config.protocol}`) .option('-p, --port ', `Server port. Default to ${Config.port?Config.port:'80|443'}`) + .option('-d, --dist ', `Distribution folder to serve as webroot. Default to ${Config.dist}`) .option('--sslType ', `SSL provider type. Default to ${Config.sslType}`) .option('--sslCert ', `SSL certificate file. Default to ${Config.sslCert}`) .option('--sslKey ', `SSL private key file. Default to ${Config.sslKey}`) @@ -49,6 +50,7 @@ try { Config.host=commander.host || Config.host Config.protocol=commander.protocol || Config.protocol || 'http' Config.port=parseInt(commander.port) || parseInt(Config.port) || (Config.protocol==='http'?80:Config.protocol==='https'?443:undefined) // 端口默认为 http:80, https:443, httpall: 80|443 + Config.dist = commander.dist || Config.dist || 'dist' Config.sslType = commander.sslType || Config.sslType Config.sslCert=commander.sslCert || Config.sslCert Config.sslKey=commander.sslKey || Config.sslKey @@ -89,7 +91,7 @@ async function init(){ /*** 设置全局对象 ***/ server.use(require('compression')()) /*** 路由 ***/ - server.use(require('express').static(path.join(process.cwd(), 'dist'), {index: 'index.html'})) + server.use(require('express').static(path.join(process.cwd(), wo.Config.dist), {index: 'index.html'})) // server.use(require('serve-favicon')(path.join(__dirname, 'public', 'favicon.ico'))) // uncomment after placing your favicon in /public let ipv4 = getMyIp()