debug more
This commit is contained in:
@@ -20,178 +20,189 @@ async function applicationConfiguration(traefik: any, remoteId: string | null =
|
|||||||
const configurableApplications = []
|
const configurableApplications = []
|
||||||
if (applications.length > 0) {
|
if (applications.length > 0) {
|
||||||
for (const application of applications) {
|
for (const application of applications) {
|
||||||
const {
|
try {
|
||||||
fqdn,
|
const {
|
||||||
id,
|
fqdn,
|
||||||
port,
|
id,
|
||||||
buildPack,
|
port,
|
||||||
dockerComposeConfiguration,
|
buildPack,
|
||||||
destinationDocker,
|
dockerComposeConfiguration,
|
||||||
destinationDockerId,
|
destinationDocker,
|
||||||
settings: { previews, dualCerts, isCustomSSL }
|
destinationDockerId,
|
||||||
} = application;
|
settings: { previews, dualCerts, isCustomSSL }
|
||||||
if (destinationDockerId) {
|
} = application;
|
||||||
const { network, id: dockerId } = destinationDocker;
|
if (destinationDockerId) {
|
||||||
const isRunning = true;
|
const { network, id: dockerId } = destinationDocker;
|
||||||
if (buildPack === 'compose') {
|
const isRunning = true;
|
||||||
console.log(dockerComposeConfiguration)
|
if (buildPack === 'compose') {
|
||||||
const services = Object.entries(JSON.parse(dockerComposeConfiguration))
|
console.log(dockerComposeConfiguration)
|
||||||
console.log(services)
|
const services = Object.entries(JSON.parse(dockerComposeConfiguration))
|
||||||
if (services.length > 0) {
|
console.log(services)
|
||||||
for (const service of services) {
|
if (services.length > 0) {
|
||||||
const [key, value] = service
|
for (const service of services) {
|
||||||
if (key && value && value.fqdn) {
|
const [key, value] = service
|
||||||
const { fqdn } = value
|
if (key && value && value.fqdn) {
|
||||||
const domain = getDomain(fqdn);
|
const { fqdn } = value
|
||||||
const nakedDomain = domain.replace(/^www\./, '');
|
const domain = getDomain(fqdn);
|
||||||
const isHttps = fqdn.startsWith('https://');
|
const nakedDomain = domain.replace(/^www\./, '');
|
||||||
const isWWW = fqdn.includes('www.');
|
const isHttps = fqdn.startsWith('https://');
|
||||||
configurableApplications.push({
|
const isWWW = fqdn.includes('www.');
|
||||||
id: `${id}-${key}`,
|
configurableApplications.push({
|
||||||
container: `${id}-${key}`,
|
id: `${id}-${key}`,
|
||||||
port: value.customPort ? value.customPort : port || 3000,
|
container: `${id}-${key}`,
|
||||||
domain,
|
port: value.customPort ? value.customPort : port || 3000,
|
||||||
nakedDomain,
|
domain,
|
||||||
isRunning,
|
nakedDomain,
|
||||||
isHttps,
|
isRunning,
|
||||||
isWWW,
|
isHttps,
|
||||||
isDualCerts: dualCerts,
|
isWWW,
|
||||||
isCustomSSL,
|
isDualCerts: dualCerts,
|
||||||
pathPrefix: '/'
|
isCustomSSL,
|
||||||
});
|
pathPrefix: '/'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
if (fqdn) {
|
||||||
}
|
const domain = getDomain(fqdn);
|
||||||
if (fqdn) {
|
const nakedDomain = domain.replace(/^www\./, '');
|
||||||
const domain = getDomain(fqdn);
|
const isHttps = fqdn.startsWith('https://');
|
||||||
const nakedDomain = domain.replace(/^www\./, '');
|
const isWWW = fqdn.includes('www.');
|
||||||
const isHttps = fqdn.startsWith('https://');
|
if (isRunning) {
|
||||||
const isWWW = fqdn.includes('www.');
|
configurableApplications.push({
|
||||||
if (isRunning) {
|
id,
|
||||||
configurableApplications.push({
|
container: id,
|
||||||
id,
|
port: port || 3000,
|
||||||
container: id,
|
domain,
|
||||||
port: port || 3000,
|
nakedDomain,
|
||||||
domain,
|
isRunning,
|
||||||
nakedDomain,
|
isHttps,
|
||||||
isRunning,
|
isWWW,
|
||||||
isHttps,
|
isDualCerts: dualCerts,
|
||||||
isWWW,
|
isCustomSSL,
|
||||||
isDualCerts: dualCerts,
|
pathPrefix: '/'
|
||||||
isCustomSSL,
|
});
|
||||||
pathPrefix: '/'
|
}
|
||||||
});
|
if (previews) {
|
||||||
}
|
const { stdout } = await executeDockerCmd({ dockerId, command: `docker container ls --filter="status=running" --filter="network=${network}" --filter="name=${id}-" --format="{{json .Names}}"` })
|
||||||
if (previews) {
|
const containers = stdout
|
||||||
const { stdout } = await executeDockerCmd({ dockerId, command: `docker container ls --filter="status=running" --filter="network=${network}" --filter="name=${id}-" --format="{{json .Names}}"` })
|
.trim()
|
||||||
const containers = stdout
|
.split('\n')
|
||||||
.trim()
|
.filter((a) => a)
|
||||||
.split('\n')
|
.map((c) => c.replace(/"/g, ''));
|
||||||
.filter((a) => a)
|
if (containers.length > 0) {
|
||||||
.map((c) => c.replace(/"/g, ''));
|
for (const container of containers) {
|
||||||
if (containers.length > 0) {
|
const previewDomain = `${container.split('-')[1]}.${domain}`;
|
||||||
for (const container of containers) {
|
const nakedDomain = previewDomain.replace(/^www\./, '');
|
||||||
const previewDomain = `${container.split('-')[1]}.${domain}`;
|
configurableApplications.push({
|
||||||
const nakedDomain = previewDomain.replace(/^www\./, '');
|
id: container,
|
||||||
configurableApplications.push({
|
container,
|
||||||
id: container,
|
port: port || 3000,
|
||||||
container,
|
domain: previewDomain,
|
||||||
port: port || 3000,
|
isRunning,
|
||||||
domain: previewDomain,
|
nakedDomain,
|
||||||
isRunning,
|
isHttps,
|
||||||
nakedDomain,
|
isWWW,
|
||||||
isHttps,
|
isDualCerts: dualCerts,
|
||||||
isWWW,
|
isCustomSSL,
|
||||||
isDualCerts: dualCerts,
|
pathPrefix: '/'
|
||||||
isCustomSSL,
|
});
|
||||||
pathPrefix: '/'
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('cannot create traefik configuration for application', application.id)
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const application of configurableApplications) {
|
for (const application of configurableApplications) {
|
||||||
let { id, port, isCustomSSL, pathPrefix, isHttps, nakedDomain, isWWW, domain, dualCerts } = application
|
let { id, port, isCustomSSL, pathPrefix, isHttps, nakedDomain, isWWW, domain, dualCerts } = application
|
||||||
if (isHttps) {
|
try {
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
if (isHttps) {
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
||||||
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
||||||
if (dualCerts) {
|
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
if (dualCerts) {
|
||||||
entrypoints: ['websecure'],
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
rule: `(Host(\`${nakedDomain}\`) || Host(\`www.${nakedDomain}\`))${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
entrypoints: ['websecure'],
|
||||||
service: `${id}`,
|
rule: `(Host(\`${nakedDomain}\`) || Host(\`www.${nakedDomain}\`))${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
tls: isCustomSSL ? true : {
|
service: `${id}`,
|
||||||
certresolver: 'letsencrypt'
|
tls: isCustomSSL ? true : {
|
||||||
},
|
certresolver: 'letsencrypt'
|
||||||
middlewares: []
|
},
|
||||||
};
|
middlewares: []
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
if (isWWW) {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: isCustomSSL ? true : {
|
||||||
|
certresolver: 'letsencrypt'
|
||||||
|
},
|
||||||
|
middlewares: []
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: {
|
||||||
|
domains: {
|
||||||
|
main: `${domain}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
middlewares: ['redirect-to-www']
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
||||||
|
} else {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: {
|
||||||
|
domains: {
|
||||||
|
main: `${domain}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
middlewares: ['redirect-to-non-www']
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`${domain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: isCustomSSL ? true : {
|
||||||
|
certresolver: 'letsencrypt'
|
||||||
|
},
|
||||||
|
middlewares: []
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isWWW) {
|
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix, 'https-to-http')
|
||||||
entrypoints: ['websecure'],
|
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: isCustomSSL ? true : {
|
|
||||||
certresolver: 'letsencrypt'
|
|
||||||
},
|
|
||||||
middlewares: []
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: {
|
|
||||||
domains: {
|
|
||||||
main: `${domain}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
middlewares: ['redirect-to-www']
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
|
||||||
} else {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: {
|
|
||||||
domains: {
|
|
||||||
main: `${domain}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
middlewares: ['redirect-to-non-www']
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`${domain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: isCustomSSL ? true : {
|
|
||||||
certresolver: 'letsencrypt'
|
|
||||||
},
|
|
||||||
middlewares: []
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix, 'https-to-http')
|
|
||||||
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
|
||||||
|
|
||||||
if (!dualCerts) {
|
if (!dualCerts) {
|
||||||
if (isWWW) {
|
if (isWWW) {
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-www');
|
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-www');
|
||||||
} else {
|
} else {
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-non-www');
|
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-non-www');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error generating traefik config for ' + id);
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,82 +235,185 @@ async function serviceConfiguration(traefik: any, remoteId: string | null = null
|
|||||||
const configurableServices = []
|
const configurableServices = []
|
||||||
if (services.length > 0) {
|
if (services.length > 0) {
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
let {
|
try {
|
||||||
fqdn,
|
let {
|
||||||
id,
|
fqdn,
|
||||||
type,
|
id,
|
||||||
destinationDockerId,
|
type,
|
||||||
dualCerts,
|
destinationDockerId,
|
||||||
serviceSetting
|
dualCerts,
|
||||||
} = service;
|
serviceSetting
|
||||||
if (destinationDockerId) {
|
} = service;
|
||||||
const templates = await getTemplates();
|
if (destinationDockerId) {
|
||||||
let found = templates.find((a) => a.type === type);
|
const templates = await getTemplates();
|
||||||
if (found) {
|
let found = templates.find((a) => a.type === type);
|
||||||
found = JSON.parse(JSON.stringify(found).replaceAll('$$id', id));
|
if (found) {
|
||||||
for (const oneService of Object.keys(found.services)) {
|
found = JSON.parse(JSON.stringify(found).replaceAll('$$id', id));
|
||||||
const isProxyConfiguration = found.services[oneService].proxy;
|
for (const oneService of Object.keys(found.services)) {
|
||||||
if (isProxyConfiguration) {
|
const isProxyConfiguration = found.services[oneService].proxy;
|
||||||
const { proxy } = found.services[oneService];
|
if (isProxyConfiguration) {
|
||||||
for (let configuration of proxy) {
|
const { proxy } = found.services[oneService];
|
||||||
const publicPort = service[type]?.publicPort;
|
for (let configuration of proxy) {
|
||||||
if (configuration.domain) {
|
const publicPort = service[type]?.publicPort;
|
||||||
const setting = serviceSetting.find((a) => a.variableName === configuration.domain);
|
if (configuration.domain) {
|
||||||
configuration.domain = configuration.domain.replace(configuration.domain, setting.value);
|
const setting = serviceSetting.find((a) => a.variableName === configuration.domain);
|
||||||
|
configuration.domain = configuration.domain.replace(configuration.domain, setting.value);
|
||||||
|
}
|
||||||
|
const foundPortVariable = serviceSetting.find((a) => a.name.toLowerCase() === 'port')
|
||||||
|
if (foundPortVariable) {
|
||||||
|
configuration.port = foundPortVariable.value
|
||||||
|
}
|
||||||
|
if (fqdn) {
|
||||||
|
configurableServices.push({
|
||||||
|
id: oneService,
|
||||||
|
publicPort,
|
||||||
|
fqdn,
|
||||||
|
dualCerts,
|
||||||
|
configuration,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const foundPortVariable = serviceSetting.find((a) => a.name.toLowerCase() === 'port')
|
} else {
|
||||||
if (foundPortVariable) {
|
if (found.services[oneService].ports && found.services[oneService].ports.length > 0) {
|
||||||
configuration.port = foundPortVariable.value
|
let port = found.services[oneService].ports[0]
|
||||||
}
|
const foundPortVariable = serviceSetting.find((a) => a.name.toLowerCase() === 'port')
|
||||||
if (fqdn) {
|
if (foundPortVariable) {
|
||||||
configurableServices.push({
|
port = foundPortVariable.value
|
||||||
id: oneService,
|
}
|
||||||
publicPort,
|
if (fqdn) {
|
||||||
fqdn,
|
configurableServices.push({
|
||||||
dualCerts,
|
id: oneService,
|
||||||
configuration,
|
configuration: {
|
||||||
});
|
port
|
||||||
}
|
},
|
||||||
}
|
fqdn,
|
||||||
} else {
|
dualCerts,
|
||||||
if (found.services[oneService].ports && found.services[oneService].ports.length > 0) {
|
});
|
||||||
let port = found.services[oneService].ports[0]
|
}
|
||||||
const foundPortVariable = serviceSetting.find((a) => a.name.toLowerCase() === 'port')
|
|
||||||
if (foundPortVariable) {
|
|
||||||
port = foundPortVariable.value
|
|
||||||
}
|
|
||||||
if (fqdn) {
|
|
||||||
configurableServices.push({
|
|
||||||
id: oneService,
|
|
||||||
configuration: {
|
|
||||||
port
|
|
||||||
},
|
|
||||||
fqdn,
|
|
||||||
dualCerts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error generating traefik config for ' + service.id);
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const service of configurableServices) {
|
for (const service of configurableServices) {
|
||||||
let { id, fqdn, dualCerts, configuration, isCustomSSL = false } = service
|
let { id, fqdn, dualCerts, configuration, isCustomSSL = false } = service
|
||||||
let port, pathPrefix, customDomain;
|
try {
|
||||||
if (configuration) {
|
let port, pathPrefix, customDomain;
|
||||||
port = configuration?.port;
|
if (configuration) {
|
||||||
pathPrefix = configuration?.pathPrefix || null;
|
port = configuration?.port;
|
||||||
customDomain = configuration?.domain;
|
pathPrefix = configuration?.pathPrefix || null;
|
||||||
}
|
customDomain = configuration?.domain;
|
||||||
if (customDomain) {
|
}
|
||||||
fqdn = customDomain
|
if (customDomain) {
|
||||||
|
fqdn = customDomain
|
||||||
|
}
|
||||||
|
const domain = getDomain(fqdn);
|
||||||
|
const nakedDomain = domain.replace(/^www\./, '');
|
||||||
|
const isHttps = fqdn.startsWith('https://');
|
||||||
|
const isWWW = fqdn.includes('www.');
|
||||||
|
if (isHttps) {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
||||||
|
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
||||||
|
if (dualCerts) {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `(Host(\`${nakedDomain}\`) || Host(\`www.${nakedDomain}\`))${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: isCustomSSL ? true : {
|
||||||
|
certresolver: 'letsencrypt'
|
||||||
|
},
|
||||||
|
middlewares: []
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
if (isWWW) {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: isCustomSSL ? true : {
|
||||||
|
certresolver: 'letsencrypt'
|
||||||
|
},
|
||||||
|
middlewares: []
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: {
|
||||||
|
domains: {
|
||||||
|
main: `${domain}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
middlewares: ['redirect-to-www']
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
||||||
|
} else {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: {
|
||||||
|
domains: {
|
||||||
|
main: `${domain}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
middlewares: ['redirect-to-non-www']
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
||||||
|
entrypoints: ['websecure'],
|
||||||
|
rule: `Host(\`${domain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
||||||
|
service: `${id}`,
|
||||||
|
tls: isCustomSSL ? true : {
|
||||||
|
certresolver: 'letsencrypt'
|
||||||
|
},
|
||||||
|
middlewares: []
|
||||||
|
};
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix, 'https-to-http')
|
||||||
|
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
||||||
|
|
||||||
|
if (!dualCerts) {
|
||||||
|
if (isWWW) {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-www');
|
||||||
|
} else {
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
||||||
|
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-non-www');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error generating router for', id);
|
||||||
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function coolifyConfiguration(traefik: any) {
|
||||||
|
try {
|
||||||
|
const { fqdn, dualCerts } = await prisma.setting.findFirst();
|
||||||
|
if (fqdn) {
|
||||||
const domain = getDomain(fqdn);
|
const domain = getDomain(fqdn);
|
||||||
const nakedDomain = domain.replace(/^www\./, '');
|
const nakedDomain = domain.replace(/^www\./, '');
|
||||||
const isHttps = fqdn.startsWith('https://');
|
const isHttps = fqdn.startsWith('https://');
|
||||||
const isWWW = fqdn.includes('www.');
|
const isWWW = fqdn.includes('www.');
|
||||||
|
const id = isDev ? 'host.docker.internal' : 'coolify'
|
||||||
|
const container = isDev ? 'host.docker.internal' : 'coolify'
|
||||||
|
const port = 3000
|
||||||
|
const pathPrefix = '/'
|
||||||
|
const isCustomSSL = false
|
||||||
if (isHttps) {
|
if (isHttps) {
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
||||||
@@ -377,108 +491,10 @@ async function serviceConfiguration(traefik: any, remoteId: string | null = null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
async function coolifyConfiguration(traefik: any) {
|
|
||||||
const { fqdn, dualCerts } = await prisma.setting.findFirst();
|
|
||||||
let coolifyConfigurations = []
|
|
||||||
if (fqdn) {
|
|
||||||
const domain = getDomain(fqdn);
|
|
||||||
const nakedDomain = domain.replace(/^www\./, '');
|
|
||||||
const isHttps = fqdn.startsWith('https://');
|
|
||||||
const isWWW = fqdn.includes('www.');
|
|
||||||
coolifyConfigurations.push({
|
|
||||||
id: isDev ? 'host.docker.internal' : 'coolify',
|
|
||||||
container: isDev ? 'host.docker.internal' : 'coolify',
|
|
||||||
port: 3000,
|
|
||||||
domain,
|
|
||||||
nakedDomain,
|
|
||||||
isHttps,
|
|
||||||
isWWW,
|
|
||||||
isDualCerts: dualCerts,
|
|
||||||
pathPrefix: '/'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
for (const coolify of coolifyConfigurations) {
|
console.log('Cannot generate traefik config for Coolify.')
|
||||||
const { id, pathPrefix, port, domain, nakedDomain, isHttps, isWWW, isDualCerts, scriptName, type, isCustomSSL } = coolify;
|
console.log(error)
|
||||||
if (isHttps) {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}-secure`, nakedDomain, pathPrefix, 'http-to-https')
|
|
||||||
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
|
||||||
if (dualCerts) {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `(Host(\`${nakedDomain}\`) || Host(\`www.${nakedDomain}\`))${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: isCustomSSL ? true : {
|
|
||||||
certresolver: 'letsencrypt'
|
|
||||||
},
|
|
||||||
middlewares: []
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
if (isWWW) {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: isCustomSSL ? true : {
|
|
||||||
certresolver: 'letsencrypt'
|
|
||||||
},
|
|
||||||
middlewares: []
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: {
|
|
||||||
domains: {
|
|
||||||
main: `${domain}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
middlewares: ['redirect-to-www']
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
|
||||||
} else {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure-www`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`www.${nakedDomain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: {
|
|
||||||
domains: {
|
|
||||||
main: `${domain}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
middlewares: ['redirect-to-non-www']
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = {
|
|
||||||
entrypoints: ['websecure'],
|
|
||||||
rule: `Host(\`${domain}\`)${pathPrefix ? ` && PathPrefix(\`${pathPrefix}\`)` : ''}`,
|
|
||||||
service: `${id}`,
|
|
||||||
tls: isCustomSSL ? true : {
|
|
||||||
certresolver: 'letsencrypt'
|
|
||||||
},
|
|
||||||
middlewares: []
|
|
||||||
};
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`] = generateHttpRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix)
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`] = generateProtocolRedirectRouter(`${id}-${port || 'default'}`, nakedDomain, pathPrefix, 'https-to-http')
|
|
||||||
traefik.http.services[`${id}-${port || 'default'}`] = generateLoadBalancerService(id, port)
|
|
||||||
|
|
||||||
if (!dualCerts) {
|
|
||||||
if (isWWW) {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-www');
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-www');
|
|
||||||
} else {
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}`].middlewares.push('redirect-to-non-www');
|
|
||||||
traefik.http.routers[`${id}-${port || 'default'}-secure`].middlewares.push('redirect-to-non-www');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function generateLoadBalancerService(id, port) {
|
function generateLoadBalancerService(id, port) {
|
||||||
|
Reference in New Issue
Block a user