feat: www <-> non-www redirection
This commit is contained in:
		@@ -7,6 +7,7 @@ import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import {
 | 
			
		||||
	configureSimpleServiceProxyOn,
 | 
			
		||||
	reloadHaproxy,
 | 
			
		||||
	setWwwRedirection,
 | 
			
		||||
	startHttpProxy,
 | 
			
		||||
	startTcpProxy
 | 
			
		||||
} from '$lib/haproxy';
 | 
			
		||||
@@ -86,13 +87,13 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
		try {
 | 
			
		||||
			await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
 | 
			
		||||
			await configureSimpleServiceProxyOn({ id, domain, port: consolePort });
 | 
			
		||||
 | 
			
		||||
			await db.updateMinioService({ id, publicPort });
 | 
			
		||||
			await startHttpProxy(destinationDocker, id, publicPort, apiPort);
 | 
			
		||||
 | 
			
		||||
			if (isHttps) {
 | 
			
		||||
				await letsEncrypt({ domain, id });
 | 
			
		||||
			}
 | 
			
		||||
			await setWwwRedirection(fqdn);
 | 
			
		||||
			await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
			return {
 | 
			
		||||
				status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs';
 | 
			
		||||
import yaml from 'js-yaml';
 | 
			
		||||
import type { RequestHandler } from '@sveltejs/kit';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy } from '$lib/haproxy';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';
 | 
			
		||||
import { getDomain } from '$lib/components/common';
 | 
			
		||||
import { PrismaErrorHandler } from '$lib/database';
 | 
			
		||||
 | 
			
		||||
@@ -52,6 +52,7 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			if (isHttps) {
 | 
			
		||||
				await letsEncrypt({ domain, id });
 | 
			
		||||
			}
 | 
			
		||||
			await setWwwRedirection(fqdn);
 | 
			
		||||
			await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
			return {
 | 
			
		||||
				status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs';
 | 
			
		||||
import yaml from 'js-yaml';
 | 
			
		||||
import type { RequestHandler } from '@sveltejs/kit';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy } from '$lib/haproxy';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';
 | 
			
		||||
import { getDomain } from '$lib/components/common';
 | 
			
		||||
import { PrismaErrorHandler } from '$lib/database';
 | 
			
		||||
 | 
			
		||||
@@ -185,6 +185,7 @@ COPY ./init-db.sh /docker-entrypoint-initdb.d/init-db.sh`;
 | 
			
		||||
		if (isHttps) {
 | 
			
		||||
			await letsEncrypt({ domain, id });
 | 
			
		||||
		}
 | 
			
		||||
		await setWwwRedirection(fqdn);
 | 
			
		||||
		await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
		return {
 | 
			
		||||
			status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs';
 | 
			
		||||
import yaml from 'js-yaml';
 | 
			
		||||
import type { RequestHandler } from '@sveltejs/kit';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy } from '$lib/haproxy';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';
 | 
			
		||||
import { getDomain } from '$lib/components/common';
 | 
			
		||||
import { getServiceImage, PrismaErrorHandler } from '$lib/database';
 | 
			
		||||
 | 
			
		||||
@@ -70,6 +70,7 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			if (isHttps) {
 | 
			
		||||
				await letsEncrypt({ domain, id });
 | 
			
		||||
			}
 | 
			
		||||
			await setWwwRedirection(fqdn);
 | 
			
		||||
			await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
			return {
 | 
			
		||||
				status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs';
 | 
			
		||||
import yaml from 'js-yaml';
 | 
			
		||||
import type { RequestHandler } from '@sveltejs/kit';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy } from '$lib/haproxy';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';
 | 
			
		||||
import { getDomain } from '$lib/components/common';
 | 
			
		||||
import { PrismaErrorHandler } from '$lib/database';
 | 
			
		||||
 | 
			
		||||
@@ -80,6 +80,7 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			if (isHttps) {
 | 
			
		||||
				await letsEncrypt({ domain, id });
 | 
			
		||||
			}
 | 
			
		||||
			await setWwwRedirection(fqdn);
 | 
			
		||||
			await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
			return {
 | 
			
		||||
				status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs';
 | 
			
		||||
import yaml from 'js-yaml';
 | 
			
		||||
import type { RequestHandler } from '@sveltejs/kit';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy } from '$lib/haproxy';
 | 
			
		||||
import { configureSimpleServiceProxyOn, reloadHaproxy, setWwwRedirection } from '$lib/haproxy';
 | 
			
		||||
import { getDomain } from '$lib/components/common';
 | 
			
		||||
import { PrismaErrorHandler } from '$lib/database';
 | 
			
		||||
 | 
			
		||||
@@ -117,6 +117,7 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			if (isHttps) {
 | 
			
		||||
				await letsEncrypt({ domain, id });
 | 
			
		||||
			}
 | 
			
		||||
			await setWwwRedirection(fqdn);
 | 
			
		||||
			await reloadHaproxy(destinationDocker.engine);
 | 
			
		||||
			return {
 | 
			
		||||
				status: 200
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ import {
 | 
			
		||||
	forceSSLOffApplication,
 | 
			
		||||
	forceSSLOnApplication,
 | 
			
		||||
	reloadHaproxy,
 | 
			
		||||
	removeWwwRedirection,
 | 
			
		||||
	setWwwRedirection,
 | 
			
		||||
	startCoolifyProxy
 | 
			
		||||
} from '$lib/haproxy';
 | 
			
		||||
import { letsEncrypt } from '$lib/letsencrypt';
 | 
			
		||||
@@ -45,9 +47,10 @@ export const del: RequestHandler = async (event) => {
 | 
			
		||||
	const { fqdn } = await event.request.json();
 | 
			
		||||
 | 
			
		||||
	try {
 | 
			
		||||
		await db.prisma.setting.update({ where: { fqdn }, data: { fqdn: null } });
 | 
			
		||||
		const domain = getDomain(fqdn);
 | 
			
		||||
		await configureCoolifyProxyOff({ domain });
 | 
			
		||||
		await db.prisma.setting.update({ where: { fqdn }, data: { fqdn: null } });
 | 
			
		||||
		await configureCoolifyProxyOff(fqdn);
 | 
			
		||||
		await removeWwwRedirection(domain);
 | 
			
		||||
		return {
 | 
			
		||||
			status: 201
 | 
			
		||||
		};
 | 
			
		||||
@@ -77,9 +80,10 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			await db.prisma.setting.update({ where: { id }, data: { isRegistrationEnabled } });
 | 
			
		||||
		}
 | 
			
		||||
		if (oldFqdn && oldFqdn !== fqdn) {
 | 
			
		||||
			const oldDomain = getDomain(oldFqdn);
 | 
			
		||||
			if (oldFqdn) {
 | 
			
		||||
				await configureCoolifyProxyOff({ domain: oldDomain });
 | 
			
		||||
				const oldDomain = getDomain(oldFqdn);
 | 
			
		||||
				await configureCoolifyProxyOff(oldFqdn);
 | 
			
		||||
				await removeWwwRedirection(oldDomain);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if (fqdn) {
 | 
			
		||||
@@ -88,7 +92,8 @@ export const post: RequestHandler = async (event) => {
 | 
			
		||||
			const domain = getDomain(fqdn);
 | 
			
		||||
			const isHttps = fqdn.startsWith('https://');
 | 
			
		||||
			if (domain) {
 | 
			
		||||
				await configureCoolifyProxyOn({ domain });
 | 
			
		||||
				await configureCoolifyProxyOn(fqdn);
 | 
			
		||||
				await setWwwRedirection(fqdn);
 | 
			
		||||
				if (isHttps && !dev) {
 | 
			
		||||
					await letsEncrypt({ domain, isCoolify: true });
 | 
			
		||||
					await forceSSLOnApplication({ domain });
 | 
			
		||||
 
 | 
			
		||||
@@ -106,7 +106,7 @@
 | 
			
		||||
			<div class="px-4 sm:px-6">
 | 
			
		||||
				<div class="flex space-x-4 py-4 px-4">
 | 
			
		||||
					<p class="pt-2 text-base font-bold text-stone-100">Domain (FQDN)</p>
 | 
			
		||||
					<div class="justify-center text-center">
 | 
			
		||||
					<div class="justify-center">
 | 
			
		||||
						<input
 | 
			
		||||
							bind:value={fqdn}
 | 
			
		||||
							readonly={!$session.isAdmin || isFqdnSet}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user