fix: Proxy

This commit is contained in:
Andras Bacsai
2022-04-12 10:12:46 +02:00
parent 2224c22c6e
commit 08704c289a
3 changed files with 16 additions and 32 deletions

View File

@@ -1,6 +1,8 @@
import { dev } from '$app/env'; import { dev } from '$app/env';
import got, { type Got } from 'got'; import got, { type Got } from 'got';
import * as db from '$lib/database'; import * as db from '$lib/database';
import mustache from 'mustache';
import crypto from 'crypto';
import { checkContainer, checkHAProxy } from '.'; import { checkContainer, checkHAProxy } from '.';
import { asyncExecShell, getDomain, getEngine } from '$lib/common'; import { asyncExecShell, getDomain, getEngine } from '$lib/common';
import { supportedServiceTypesAndVersions } from '$lib/components/common'; import { supportedServiceTypesAndVersions } from '$lib/components/common';
@@ -262,36 +264,20 @@ export async function configureHAProxy(): Promise<void> {
redirectValue, redirectValue,
redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain
}); });
for (const service of services) { }
const { fqdn, id, type, destinationDocker, destinationDockerId, updatedAt } = service; const output = mustache.render(template, data);
if (destinationDockerId) { const newHash = crypto.createHash('md5').update(output).digest('hex');
const { engine } = destinationDocker; const { proxyHash, id } = await db.listSettings();
const found = supportedServiceTypesAndVersions.find((a) => a.name === type); if (proxyHash !== newHash) {
if (found) { await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } });
const port = found.ports.main; await haproxy.post(`v2/services/haproxy/configuration/raw`, {
const publicPort = service[type]?.publicPort; searchParams: {
const isRunning = await checkContainer(engine, id); skip_version: true
if (fqdn) { },
const domain = getDomain(fqdn); body: output,
const isHttps = fqdn.startsWith('https://'); headers: {
const isWWW = fqdn.includes('www.'); 'Content-Type': 'text/plain'
const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`; }
if (isRunning) {
data.services.push({
id,
port,
publicPort,
domain,
isRunning,
isHttps,
redirectValue,
redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain,
updatedAt: updatedAt.getTime()
}); });
} }
}
}
}
}
}
} }

View File

@@ -8,7 +8,6 @@ import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async (event) => { export const get: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
console.log(teamId);
const { id } = event.params; const { id } = event.params;
try { try {
const destination = await db.getDestination({ id, teamId }); const destination = await db.getDestination({ id, teamId });

View File

@@ -36,7 +36,6 @@
export let settings; export let settings;
onMount(() => { onMount(() => {
const { organization, id, htmlUrl } = source; const { organization, id, htmlUrl } = source;
console.log(source);
const { fqdn } = settings; const { fqdn } = settings;
const host = dev const host = dev
? 'http://localhost:3000' ? 'http://localhost:3000'