feat: www <-> non-www redirection

This commit is contained in:
Andras Bacsai
2022-02-13 22:56:37 +01:00
parent 69d3cb5dd8
commit aec1d184c8
11 changed files with 90 additions and 45 deletions

View File

@@ -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 });

View File

@@ -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}