Commit 7ec69b9c authored by nanahira's avatar nanahira

support upstream extra

parent 0af4cec1
Pipeline #26200 passed with stages
in 14 minutes and 54 seconds
......@@ -90,17 +90,18 @@ export interface RenderData {
export interface Upstream {
name: string;
servers: string[];
extra?: string[];
}
const upstreams: Upstream[] = [];
function createUpstream(domain: string, urlInputs: string[]) {
function createUpstream(domain: string, urlInputs: string[], extra: string[]) {
const urls = urlInputs.map((url) => new URL(url));
if (urls.length === 1) {
return urlInputs[0];
}
const name = `upstream_${domain.replace(/[^a-zA-Z0-9]/g, '_')}`;
upstreams.push({ name, servers: urls.map((url) => url.host) });
return `${urls[0].protocol}//${name}${urlInputs[0].slice(urls[0].origin.length)}`;
upstreams.push({ name, servers: urls.map((url) => `${url.host + (url.hash ? url.hash.replace(/[#&]/g, ' ') : '')}`), extra });
return `${urls[0].protocol}//${name}${urlInputs[0].slice(urls[0].origin.length).replace(urls[0].hash, '')}`;
}
async function getSiteData(
......@@ -166,7 +167,7 @@ async function getSiteData(
const sni = parser.getString('SNI');
specificRenderData = {
proxy: true,
upstream: createUpstream(domain, targetUrlInputs),
upstream: createUpstream(domain, targetUrlInputs, parser.getArray('UPSTREAM_EXTRA')),
noVerifyCerts: parser.getBoolean('NO_VERIFY_CERTS'),
noBuffer: parser.getBoolean('NO_BUFFER'),
sni: sni === '1',
......
......@@ -149,6 +149,9 @@ http {
{{#servers}}
server {{.}};
{{/servers}}
{{#extra}}
{{.}}
{{/extra}}
}
{{/upstreams}}
......
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