支持 vhosts 配置参数
This commit is contained in:
parent
c3fc3e2c88
commit
3b5ef883f1
@ -19,4 +19,8 @@ module.exports={
|
|||||||
password: '', // 登录用户密码
|
password: '', // 登录用户密码
|
||||||
key: `${process.env.HOME}/.ssh/id_rsa`, // 登录用户私钥文件
|
key: `${process.env.HOME}/.ssh/id_rsa`, // 登录用户私钥文件
|
||||||
},
|
},
|
||||||
|
|
||||||
|
vhosts: [
|
||||||
|
{ webroot: 'dist', webindex: 'index.html', domainList: ['']}
|
||||||
|
],
|
||||||
}
|
}
|
22
server.js
22
server.js
@ -79,7 +79,7 @@ async function init(){ /*** 设置全局对象 ***/
|
|||||||
store: require('greenlock-store-fs'),
|
store: require('greenlock-store-fs'),
|
||||||
email: 'ssl@faronear.org',
|
email: 'ssl@faronear.org',
|
||||||
approvedDomains: wo.Config.sslDomainList,
|
approvedDomains: wo.Config.sslDomainList,
|
||||||
configDir: path.resolve(__dirname, 'ssl'),
|
configDir: path.resolve(process.cwd(), 'ssl'),
|
||||||
app: server,
|
app: server,
|
||||||
}) : null
|
}) : null
|
||||||
|
|
||||||
@ -91,12 +91,30 @@ async function init(){ /*** 设置全局对象 ***/
|
|||||||
server.use(require('compression')())
|
server.use(require('compression')())
|
||||||
|
|
||||||
/*** 路由 ***/
|
/*** 路由 ***/
|
||||||
|
// vhost 匹配了域名,就执行;不匹配,就next()
|
||||||
|
// express.static 找到了具体文件,就返回;找不到,就next()
|
||||||
|
// 所以,如果 vhost匹配了域名,且static找到了文件,就结束了。如果 vhost 匹配了域名,但static找不到文件,就继续往下。
|
||||||
|
if (!wo.Config.vhosts) {
|
||||||
server.use(require('express').static(path.join(process.cwd(), wo.Config.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
|
// server.use(require('serve-favicon')(path.join(process.cwd(), 'public', 'favicon.ico'))) // uncomment after placing your favicon in /public
|
||||||
|
}else {
|
||||||
|
let vhost = require('vhost')
|
||||||
|
for (let h of wo.Config.vhosts) {
|
||||||
|
for (let domain of h.domainList) {
|
||||||
|
server.use(vhost(domain, express.static(path.join(process.cwd(), h.webroot), {index: h.webindex})))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** 路由 ***/
|
||||||
|
//var router = express.Router()
|
||||||
|
//router.get('/path', function(req,res) { res.redirect('target') })
|
||||||
|
//server.use(router)
|
||||||
|
|
||||||
let ipv4 = getMyIp()
|
let ipv4 = getMyIp()
|
||||||
|
|
||||||
/*** 启动 Web 服务 ***/
|
/*** 启动 Web 服务 ***/
|
||||||
|
let webServer
|
||||||
if ('http' === wo.Config.protocol) {
|
if ('http' === wo.Config.protocol) {
|
||||||
webServer = require('http').createServer(server).listen(wo.Config.port, function (err) {
|
webServer = require('http').createServer(server).listen(wo.Config.port, function (err) {
|
||||||
if (err) console.log(err)
|
if (err) console.log(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user