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.
Site variables should be followed after `SITE_<domain>_`.
- `SITE_mycard.moe` Site and origin. eg. `SITE_mycard.moe=http://localhost:3000`
- `PORT`
- `HTTPS` Enable HTTPS and specify cert.
- `HTTPS_PORT`
- `HTTPS_NOREDIR` Disable redirect to HTTPS.
- `HSTS` Enable HSTS.
- `HEADER` Extra header. eg. `SITE_mycard.moe_HEADER_FOO=bar`
- `DISABLE_TOP` Disable / access.
- `HTPASSWD_username` Enable basic auth, and specify username and password.
- `CORS` Enable CORS.
- `SERVER_EXTRA` Extra entry in `server`.
- `LOCATION_EXTRA` Extra entry in `location`.
......
......@@ -91,9 +91,11 @@ async function getSiteData(
input: Record<string, string> = process.env,
): Promise<SpecificRenderData> {
const parser = new Parser(`SITE_${domain}_`, input);
const [hostname, port] = domain.split(':');
const ports = [port || '80'];
let https: SiteHttps;
const httpsCert = parser.getString('HTTPS');
const domains = domain.split('+');
const domains = hostname.split('+');
if (httpsCert !== '0' && httpsCert !== 'false') {
const cert =
!httpsCert ||
......@@ -103,16 +105,21 @@ async function getSiteData(
? pickCert(domains)
: httpsCert;
if (cert) {
if (port) {
ports.pop();
}
https = {
cert,
ports: parser.getArray('HTTPS_PORT') || ['443'],
redirect: !parser.getBoolean('HTTPS_NOREDIR'),
ports: [port || '443'],
redirect: !parser.getBoolean('HTTPS_NOREDIR') && !port,
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;
if (targetUrl.protocol === 'static:') {
specificRenderData = {
......@@ -141,7 +148,7 @@ async function getSiteData(
const sni = parser.getString('SNI');
specificRenderData = {
proxy: true,
upstream: input[`SITE_${domain}`],
upstream: targetUrlInput,
noVerifyCerts: parser.getBoolean('NO_VERIFY_CERTS'),
noBuffer: parser.getBoolean('NO_BUFFER'),
sni: sni === '1',
......@@ -166,7 +173,7 @@ async function getSiteData(
return {
domains: domains,
ports: parser.getArray('PORT') || ['80'],
ports,
https,
headers: Object.entries(parser.getDict('HEADER')).map(([name, value]) => ({
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