From 8d175fcb7b9cb4236572d2ff06a49c9a10968fbd Mon Sep 17 00:00:00 2001 From: Wildan M Date: Mon, 23 Sep 2024 12:43:12 +0700 Subject: [PATCH] Add www config --- package-lock.json | 4 ++-- package.json | 2 +- src/executor/nginx.js | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f1082e8..0a5de39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domcloud-bridge", - "version": "0.60.0", + "version": "0.61.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domcloud-bridge", - "version": "0.60.0", + "version": "0.61.0", "license": "MIT", "dependencies": { "cli": "^1.0.1", diff --git a/package.json b/package.json index d51fb1c..17e475f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domcloud-bridge", - "version": "0.60.0", + "version": "0.61.0", "description": "Deployment runner for DOM Cloud", "main": "app.js", "engines": { diff --git a/src/executor/nginx.js b/src/executor/nginx.js index 9f19a3e..1e90f15 100644 --- a/src/executor/nginx.js +++ b/src/executor/nginx.js @@ -25,6 +25,7 @@ const locationKeys = [ "expires", "allow", "deny", "autoindex", "proxy_pass" ]; const sslNames = ["", "off", "always", "on"]; +const wwwNames = ["", "off", "always", "on"]; const unitProxy = "http://127.0.0.1:88" class NginxExecutor { @@ -122,7 +123,14 @@ class NginxExecutor { node._remove(prop); } }); - node._add('server_name', info.dom); + let wwwconf = info.config.www || wwwNames[info.www]; + if (wwwconf === "enforce" || wwwconf === "always") { + node._add('server_name', 'www.' + info.dom); + } else if (wwwconf == "on") { + node._add('server_name', 'www.' + info.dom + ' ' + info.dom); + } else { + node._add('server_name', info.dom); + } let sslconf = info.config.ssl || sslNames[info.ssl]; let httpconf = info.config.http || info.http; if (sslconf !== "enforce" && sslconf !== "always") { @@ -286,6 +294,7 @@ class NginxExecutor { } const data = { ssl: 0, // binary of 1 = HTTP, 2 = HTTPS + www: 1, // binary of 1 = apex, 2 = www http: 1, // http version (1 or 2) dom: null, ip: null, @@ -318,6 +327,10 @@ class NginxExecutor { if (node.http2 && node.http2[0]._value == "on") { data.http = 2; } + let servernames = (node.server_name[0]?._value || '').split(' '); + let hasApex = servernames.includes(domain); + let hasWww = servernames.includes('www.' + domain); + data.www = (hasApex ? 1 : 0) + (hasWww ? 2 : 0); data.root = node.root ? node.root[0]._value : ""; data.user = data.root.split('/')[2]; data.home = `/home/${data.user}/`; @@ -332,8 +345,10 @@ class NginxExecutor { delete data.config.match; delete data.config.alias; data.config.ssl = sslNames[data.ssl]; - if (data.http !== 2) + if (data.http !== 1) data.config.http = data.http; + if (data.www !== 1) + data.config.www = wwwNames[data.www]; if (!data.config.fastcgi) data.config.fastcgi = "off"; if (node.error_page) {