Commit 477b9a6e authored by nanahira's avatar nanahira

support non-standard port

parent a58072a1
Pipeline #26094 failed with stages
in 60 minutes and 1 second
...@@ -9,13 +9,13 @@ Nginx with only env var conf. ...@@ -9,13 +9,13 @@ Nginx with only env var conf.
Site variables should be followed after `SITE_<domain>_`. Site variables should be followed after `SITE_<domain>_`.
- `SITE_mycard.moe` Site and origin. eg. `SITE_mycard.moe=http://localhost:3000` - `SITE_mycard.moe` Site and origin. eg. `SITE_mycard.moe=http://localhost:3000`
- `PORT`
- `HTTPS` Enable HTTPS and specify cert. - `HTTPS` Enable HTTPS and specify cert.
- `HTTPS_PORT`
- `HTTPS_NOREDIR` Disable redirect to HTTPS. - `HTTPS_NOREDIR` Disable redirect to HTTPS.
- `HSTS` Enable HSTS. - `HSTS` Enable HSTS.
- `HEADER` Extra header. eg. `SITE_mycard.moe_HEADER_FOO=bar` - `HEADER` Extra header. eg. `SITE_mycard.moe_HEADER_FOO=bar`
- `DISABLE_TOP` Disable / access. - `DISABLE_TOP` Disable / access.
- `HTPASSWD_username` Enable basic auth, and specify username and password.
- `CORS` Enable CORS.
- `SERVER_EXTRA` Extra entry in `server`. - `SERVER_EXTRA` Extra entry in `server`.
- `LOCATION_EXTRA` Extra entry in `location`. - `LOCATION_EXTRA` Extra entry in `location`.
......
...@@ -91,9 +91,11 @@ async function getSiteData( ...@@ -91,9 +91,11 @@ async function getSiteData(
input: Record<string, string> = process.env, input: Record<string, string> = process.env,
): Promise<SpecificRenderData> { ): Promise<SpecificRenderData> {
const parser = new Parser(`SITE_${domain}_`, input); const parser = new Parser(`SITE_${domain}_`, input);
const [hostname, port] = domain.split(':');
const ports = [port || '80'];
let https: SiteHttps; let https: SiteHttps;
const httpsCert = parser.getString('HTTPS'); const httpsCert = parser.getString('HTTPS');
const domains = domain.split('+'); const domains = hostname.split('+');
if (httpsCert !== '0' && httpsCert !== 'false') { if (httpsCert !== '0' && httpsCert !== 'false') {
const cert = const cert =
!httpsCert || !httpsCert ||
...@@ -103,16 +105,21 @@ async function getSiteData( ...@@ -103,16 +105,21 @@ async function getSiteData(
? pickCert(domains) ? pickCert(domains)
: httpsCert; : httpsCert;
if (cert) { if (cert) {
if (port) {
ports.pop();
}
https = { https = {
cert, cert,
ports: parser.getArray('HTTPS_PORT') || ['443'], ports: [port || '443'],
redirect: !parser.getBoolean('HTTPS_NOREDIR'), redirect: !parser.getBoolean('HTTPS_NOREDIR') && !port,
hsts: parser.getBoolean('HSTS'), hsts: parser.getBoolean('HSTS'),
}; };
} }
} }
const targetUrl = new URL(input[`SITE_${domain}`]); const targetUrlInput = input[`SITE_${domain}`];
const targetUrlInputs = targetUrlInput.split(','); // TODO: support multiple targets as upstream
const targetUrl = new URL(targetUrlInputs[0]);
let specificRenderData: SpecificRenderData; let specificRenderData: SpecificRenderData;
if (targetUrl.protocol === 'static:') { if (targetUrl.protocol === 'static:') {
specificRenderData = { specificRenderData = {
...@@ -141,7 +148,7 @@ async function getSiteData( ...@@ -141,7 +148,7 @@ async function getSiteData(
const sni = parser.getString('SNI'); const sni = parser.getString('SNI');
specificRenderData = { specificRenderData = {
proxy: true, proxy: true,
upstream: input[`SITE_${domain}`], upstream: targetUrlInput,
noVerifyCerts: parser.getBoolean('NO_VERIFY_CERTS'), noVerifyCerts: parser.getBoolean('NO_VERIFY_CERTS'),
noBuffer: parser.getBoolean('NO_BUFFER'), noBuffer: parser.getBoolean('NO_BUFFER'),
sni: sni === '1', sni: sni === '1',
...@@ -166,7 +173,7 @@ async function getSiteData( ...@@ -166,7 +173,7 @@ async function getSiteData(
return { return {
domains: domains, domains: domains,
ports: parser.getArray('PORT') || ['80'], ports,
https, https,
headers: Object.entries(parser.getDict('HEADER')).map(([name, value]) => ({ headers: Object.entries(parser.getDict('HEADER')).map(([name, value]) => ({
name: name.replace(/_/g, '-'), name: name.replace(/_/g, '-'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment