fix: Unnecessary proxy restart
feat: Restart proxy
This commit is contained in:
parent
4487846fd7
commit
1df81b8698
@ -605,7 +605,7 @@ export async function removeWwwRedirection(domain) {
|
|||||||
export async function setWwwRedirection(fqdn) {
|
export async function setWwwRedirection(fqdn) {
|
||||||
const haproxy = await haproxyInstance();
|
const haproxy = await haproxyInstance();
|
||||||
await checkHAProxy(haproxy);
|
await checkHAProxy(haproxy);
|
||||||
const transactionId = await getNextTransactionId();
|
let transactionId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const domain = getDomain(fqdn);
|
const domain = getDomain(fqdn);
|
||||||
@ -629,6 +629,7 @@ export async function setWwwRedirection(fqdn) {
|
|||||||
nextRule = rules.data[rules.data.length - 1].index + 1;
|
nextRule = rules.data[rules.data.length - 1].index + 1;
|
||||||
}
|
}
|
||||||
const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
|
const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`;
|
||||||
|
transactionId = await getNextTransactionId();
|
||||||
await haproxy
|
await haproxy
|
||||||
.post(`v2/services/haproxy/configuration/http_request_rules`, {
|
.post(`v2/services/haproxy/configuration/http_request_rules`, {
|
||||||
searchParams: {
|
searchParams: {
|
||||||
@ -651,6 +652,6 @@ export async function setWwwRedirection(fqdn) {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
await completeTransaction(transactionId);
|
if (transactionId) await completeTransaction(transactionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
let cannotDisable = settings.fqdn && destination.engine === '/var/run/docker.sock';
|
let cannotDisable = settings.fqdn && destination.engine === '/var/run/docker.sock';
|
||||||
// let scannedApps = [];
|
// let scannedApps = [];
|
||||||
let loading = false;
|
let loading = false;
|
||||||
|
let restarting = false;
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
loading = true;
|
loading = true;
|
||||||
try {
|
try {
|
||||||
@ -102,20 +103,16 @@
|
|||||||
}
|
}
|
||||||
async function forceRestartProxy() {
|
async function forceRestartProxy() {
|
||||||
try {
|
try {
|
||||||
|
restarting = true;
|
||||||
toast.push('Coolify Proxy restarting...');
|
toast.push('Coolify Proxy restarting...');
|
||||||
await post(`/destinations/${id}/stop.json`, { engine: destination.engine });
|
await post(`/destinations/${id}/restart.json`, {
|
||||||
await post(`/destinations/${id}/settings.json`, {
|
engine: destination.engine,
|
||||||
isCoolifyProxyUsed: false,
|
fqdn: settings.fqdn
|
||||||
engine: destination.engine
|
|
||||||
});
|
});
|
||||||
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 }) {
|
} catch ({ error }) {
|
||||||
return errorNotification(error);
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -132,6 +129,12 @@
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
>{loading ? 'Saving...' : 'Save'}
|
>{loading ? 'Saving...' : 'Save'}
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
class={restarting ? '' : 'bg-red-600 hover:bg-red-500'}
|
||||||
|
disabled={restarting}
|
||||||
|
on:click|preventDefault={forceRestartProxy}
|
||||||
|
>{restarting ? 'Restarting... please wait...' : 'Force restart proxy'}</button
|
||||||
|
>
|
||||||
<!-- <button type="button" class="bg-coollabs hover:bg-coollabs-100" on:click={scanApps}
|
<!-- <button type="button" class="bg-coollabs hover:bg-coollabs-100" on:click={scanApps}
|
||||||
>Scan for applications</button
|
>Scan for applications</button
|
||||||
> -->
|
> -->
|
||||||
@ -187,7 +190,6 @@
|
|||||||
: ''
|
: ''
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
<button on:click|preventDefault={forceRestartProxy}>Force Restart Proxy</button>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
34
src/routes/destinations/[id]/restart.json.ts
Normal file
34
src/routes/destinations/[id]/restart.json.ts
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user