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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -132,6 +129,12 @@
|
||||
disabled={loading}
|
||||
>{loading ? 'Saving...' : 'Save'}
|
||||
</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}
|
||||
>Scan for applications</button
|
||||
> -->
|
||||
@ -187,7 +190,6 @@
|
||||
: ''
|
||||
}`}
|
||||
/>
|
||||
<button on:click|preventDefault={forceRestartProxy}>Force Restart Proxy</button>
|
||||
</ul>
|
||||
</div>
|
||||
</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