feat: http + h2c paralel
This commit is contained in:
parent
9837ae359f
commit
7ddac50008
@ -4,17 +4,29 @@ import { getTemplates } from '../../../lib/services';
|
|||||||
import { OnlyId } from '../../../types';
|
import { OnlyId } from '../../../types';
|
||||||
|
|
||||||
function generateServices(serviceId, containerId, port, isHttp2 = false) {
|
function generateServices(serviceId, containerId, port, isHttp2 = false) {
|
||||||
return {
|
const payload = {
|
||||||
[serviceId]: {
|
[serviceId]: {
|
||||||
loadbalancer: {
|
loadbalancer: {
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
url: `${isHttp2 ? 'h2c' : 'http'}://${containerId}:${port}`
|
url: `http://${containerId}:${port}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (isHttp2) {
|
||||||
|
payload[`${serviceId}-http2`] = {
|
||||||
|
loadbalancer: {
|
||||||
|
servers: [
|
||||||
|
{
|
||||||
|
url: `h2c://${containerId}:${port}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
}
|
}
|
||||||
function generateRouters(
|
function generateRouters(
|
||||||
serviceId,
|
serviceId,
|
||||||
@ -24,18 +36,20 @@ function generateRouters(
|
|||||||
isHttps,
|
isHttps,
|
||||||
isWWW,
|
isWWW,
|
||||||
isDualCerts,
|
isDualCerts,
|
||||||
isCustomSSL
|
isCustomSSL,
|
||||||
|
isHttp2 = false
|
||||||
) {
|
) {
|
||||||
|
let rule = `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`;
|
||||||
let http: any = {
|
let http: any = {
|
||||||
entrypoints: ['web'],
|
entrypoints: ['web'],
|
||||||
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
rule,
|
||||||
service: `${serviceId}`,
|
service: `${serviceId}`,
|
||||||
priority: 2,
|
priority: 2,
|
||||||
middlewares: []
|
middlewares: []
|
||||||
};
|
};
|
||||||
let https: any = {
|
let https: any = {
|
||||||
entrypoints: ['websecure'],
|
entrypoints: ['websecure'],
|
||||||
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
rule,
|
||||||
service: `${serviceId}`,
|
service: `${serviceId}`,
|
||||||
priority: 2,
|
priority: 2,
|
||||||
tls: {
|
tls: {
|
||||||
@ -45,14 +59,14 @@ function generateRouters(
|
|||||||
};
|
};
|
||||||
let httpWWW: any = {
|
let httpWWW: any = {
|
||||||
entrypoints: ['web'],
|
entrypoints: ['web'],
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
rule,
|
||||||
service: `${serviceId}`,
|
service: `${serviceId}`,
|
||||||
priority: 2,
|
priority: 2,
|
||||||
middlewares: []
|
middlewares: []
|
||||||
};
|
};
|
||||||
let httpsWWW: any = {
|
let httpsWWW: any = {
|
||||||
entrypoints: ['websecure'],
|
entrypoints: ['websecure'],
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
rule,
|
||||||
service: `${serviceId}`,
|
service: `${serviceId}`,
|
||||||
priority: 2,
|
priority: 2,
|
||||||
tls: {
|
tls: {
|
||||||
@ -137,6 +151,38 @@ function generateRouters(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isHttp2) {
|
||||||
|
let http2 = {
|
||||||
|
...http,
|
||||||
|
service: `${serviceId}-http2`,
|
||||||
|
rule: `${rule} && HeadersRegexp(\`Content-Type\`, \`application/grpc*\`)`
|
||||||
|
};
|
||||||
|
let http2WWW = {
|
||||||
|
...httpWWW,
|
||||||
|
service: `${serviceId}-http2`,
|
||||||
|
rule: `${rule} && HeadersRegexp(\`Content-Type\`, \`application/grpc*\`)`
|
||||||
|
};
|
||||||
|
let https2 = {
|
||||||
|
...https,
|
||||||
|
service: `${serviceId}-http2`,
|
||||||
|
rule: `${rule} && HeadersRegexp(\`Content-Type\`, \`application/grpc*\`)`
|
||||||
|
};
|
||||||
|
let https2WWW = {
|
||||||
|
...httpsWWW,
|
||||||
|
service: `${serviceId}-http2`,
|
||||||
|
rule: `${rule} && HeadersRegexp(\`Content-Type\`, \`application/grpc*\`)`
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
[`${serviceId}-${pathPrefix}`]: { ...http },
|
||||||
|
[`${serviceId}-${pathPrefix}-http2`]: { ...http2 },
|
||||||
|
[`${serviceId}-${pathPrefix}-secure`]: { ...https },
|
||||||
|
[`${serviceId}-${pathPrefix}-secure-http2`]: { ...https2 },
|
||||||
|
[`${serviceId}-${pathPrefix}-www`]: { ...httpWWW },
|
||||||
|
[`${serviceId}-${pathPrefix}-www-http2`]: { ...http2WWW },
|
||||||
|
[`${serviceId}-${pathPrefix}-secure-www`]: { ...httpsWWW },
|
||||||
|
[`${serviceId}-${pathPrefix}-secure-www-http2`]: { ...https2WWW }
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
[`${serviceId}-${pathPrefix}`]: { ...http },
|
[`${serviceId}-${pathPrefix}`]: { ...http },
|
||||||
[`${serviceId}-${pathPrefix}-secure`]: { ...https },
|
[`${serviceId}-${pathPrefix}-secure`]: { ...https },
|
||||||
@ -384,7 +430,8 @@ export async function proxyConfiguration(request: FastifyRequest<OnlyId>, remote
|
|||||||
isHttps,
|
isHttps,
|
||||||
isWWW,
|
isWWW,
|
||||||
dualCerts,
|
dualCerts,
|
||||||
isCustomSSL
|
isCustomSSL,
|
||||||
|
isHttp2
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
traefik.http.services = {
|
traefik.http.services = {
|
||||||
|
@ -734,8 +734,8 @@
|
|||||||
id="isHttp2"
|
id="isHttp2"
|
||||||
isCenter={false}
|
isCenter={false}
|
||||||
bind:setting={isHttp2}
|
bind:setting={isHttp2}
|
||||||
title="Enable HTTP/2 (h2c only)"
|
title="Enable h2c (HTTP/2 without TLS)"
|
||||||
description="Enable HTTP/2 protocol. <br><br>HTTP/2 is a major revision of the HTTP network protocol used by the World Wide Web that allows faster web page loading by reducing the number of requests needed to load a web page. <br><br>Useful for gRPC and other HTTP/2 based services."
|
description="Enable h2c protocol. <br><br>HTTP/2 is a major revision of the HTTP network protocol used by the World Wide Web that allows faster web page loading by reducing the number of requests needed to load a web page. <br><br>Useful for gRPC and other HTTP/2 based services."
|
||||||
on:click={() => changeSettings('isHttp2')}
|
on:click={() => changeSettings('isHttp2')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -756,8 +756,8 @@
|
|||||||
id="isHttp2"
|
id="isHttp2"
|
||||||
isCenter={false}
|
isCenter={false}
|
||||||
bind:setting={isHttp2}
|
bind:setting={isHttp2}
|
||||||
title="Enable HTTP/2 (h2c only)"
|
title="Enable h2c (HTTP/2 without TLS)"
|
||||||
description="Enable HTTP/2 protocol. <br><br>HTTP/2 is a major revision of the HTTP network protocol used by the World Wide Web that allows faster web page loading by reducing the number of requests needed to load a web page.<br><br>Useful for gRPC and other HTTP/2 based services."
|
description="Enable h2c protocol. <br><br>HTTP/2 is a major revision of the HTTP network protocol used by the World Wide Web that allows faster web page loading by reducing the number of requests needed to load a web page.<br><br>Useful for gRPC and other HTTP/2 based services."
|
||||||
on:click={() => changeSettings('isHttp2')}
|
on:click={() => changeSettings('isHttp2')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user