Skip to content

Commit

Permalink
fix: ensure that server names are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Oct 22, 2020
1 parent e1a4ef1 commit a5d0925
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
" "
);

const serverConfigs = DEPLOY_DOMAIN_NAMES.split(/\s/)
const normalizedDeployDomainNames = DEPLOY_DOMAIN_NAMES.split(/\s/)
.map(domainName => [domainName, `www.${domainName}`])
.flat();

const serverConfigs = normalizedDeployDomainNames
.map(domainName => [
{
domainName,
Expand All @@ -68,7 +72,7 @@ server {
ssl_certificate /etc/letsencrypt/live/${domainName}/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/${domainName}/privkey.pem; # managed by Certbot
server_name ${domainName}${normalizePortSuffix(publicPort)} www.${domainName}${normalizePortSuffix(publicPort)};
server_name ${domainName}${normalizePortSuffix(publicPort)}
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
Expand All @@ -87,13 +91,10 @@ server {
.join("\n")}
server {
${DEPLOY_DOMAIN_NAMES.split(/\s/)
${normalizedDeployDomainNames
.split(/\s/)
.map(
domainName => `\
if ($host = www.${domainName}) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = ${domainName}) {
return 301 https://$host$request_uri;
} # managed by Certbot
Expand Down

0 comments on commit a5d0925

Please sign in to comment.