diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts index d1c32acf0..62e44f45a 100644 --- a/src/lib/haproxy/index.ts +++ b/src/lib/haproxy/index.ts @@ -605,7 +605,7 @@ export async function removeWwwRedirection(domain) { export async function setWwwRedirection(fqdn) { const haproxy = await haproxyInstance(); await checkHAProxy(haproxy); - const transactionId = await getNextTransactionId(); + let transactionId; try { const domain = getDomain(fqdn); @@ -629,6 +629,7 @@ export async function setWwwRedirection(fqdn) { nextRule = rules.data[rules.data.length - 1].index + 1; } const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`; + transactionId = await getNextTransactionId(); await haproxy .post(`v2/services/haproxy/configuration/http_request_rules`, { searchParams: { @@ -651,6 +652,6 @@ export async function setWwwRedirection(fqdn) { console.log(error); throw error; } finally { - await completeTransaction(transactionId); + if (transactionId) await completeTransaction(transactionId); } } diff --git a/src/routes/destinations/[id]/_LocalDocker.svelte b/src/routes/destinations/[id]/_LocalDocker.svelte index 646752a3b..a25af53bd 100644 --- a/src/routes/destinations/[id]/_LocalDocker.svelte +++ b/src/routes/destinations/[id]/_LocalDocker.svelte @@ -14,6 +14,7 @@ let cannotDisable = settings.fqdn && destination.engine === '/var/run/docker.sock'; // let scannedApps = []; let loading = false; + let restarting = false; async function handleSubmit() { loading = true; try { @@ -102,20 +103,16 @@ } async function forceRestartProxy() { try { + restarting = true; toast.push('Coolify Proxy restarting...'); - await post(`/destinations/${id}/stop.json`, { engine: destination.engine }); - await post(`/destinations/${id}/settings.json`, { - isCoolifyProxyUsed: false, - engine: destination.engine + await post(`/destinations/${id}/restart.json`, { + engine: destination.engine, + fqdn: settings.fqdn }); - await post(`/destinations/${id}/start.json`, { engine: destination.engine }); - await post(`/destinations/${id}/settings.json`, { - isCoolifyProxyUsed: true, - engine: destination.engine - }); - window.location.reload(); } catch ({ error }) { - return errorNotification(error); + setTimeout(() => { + window.location.reload(); + }, 5000); } } @@ -132,6 +129,12 @@ disabled={loading} >{loading ? 'Saving...' : 'Save'} + @@ -187,7 +190,6 @@ : '' }`} /> - diff --git a/src/routes/destinations/[id]/restart.json.ts b/src/routes/destinations/[id]/restart.json.ts new file mode 100644 index 000000000..b3efa60da --- /dev/null +++ b/src/routes/destinations/[id]/restart.json.ts @@ -0,0 +1,34 @@ +import { getDomain, getUserDetails } from '$lib/common'; +import { ErrorHandler } from '$lib/database'; +import * as db from '$lib/database'; +import { + configureCoolifyProxyOn, + forceSSLOnApplication, + setWwwRedirection, + startCoolifyProxy, + stopCoolifyProxy +} from '$lib/haproxy'; +import type { RequestHandler } from '@sveltejs/kit'; + +export const post: RequestHandler = async (event) => { + const { teamId, status, body } = await getUserDetails(event); + if (status === 401) return { status, body }; + + const { engine, fqdn } = await event.request.json(); + + try { + const domain = getDomain(fqdn); + await stopCoolifyProxy(engine); + await startCoolifyProxy(engine); + await db.setDestinationSettings({ engine, isCoolifyProxyUsed: true }); + await configureCoolifyProxyOn(fqdn); + await setWwwRedirection(fqdn); + const isHttps = fqdn.startsWith('https://'); + if (isHttps) await forceSSLOnApplication({ domain }); + return { + status: 200 + }; + } catch (error) { + return ErrorHandler(error); + } +};