From 0fda0c3fbcbee1bf804cfe52b954ee37ef06d8c3 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Tue, 16 Jan 2024 15:31:14 +0100 Subject: [PATCH] Add more custom domain context --- client/middleware/custom-domain.global.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/middleware/custom-domain.global.js b/client/middleware/custom-domain.global.js index 24d2381..c0dbc46 100644 --- a/client/middleware/custom-domain.global.js +++ b/client/middleware/custom-domain.global.js @@ -12,7 +12,8 @@ const customDomainHeaderName = 'user-custom-domain' */ const customDomainAllowedRoutes = ['forms-slug'] -function redirectToMainDomain() { +function redirectToMainDomain(reason = 'unknown') { + console.warn('Redirecting to main domain', { reason }) return navigateTo(useRuntimeConfig().public.appUrl + '?utm_source=failed_custom_domain_redirect', { redirectCode: 301, external: true }) } @@ -28,17 +29,17 @@ export default defineNuxtRouteMiddleware((to, from) => { 'customDomainHeaderValue': customDomainHeaderValue, 'host': getDomain(getHost()), }) - return redirectToMainDomain() + return redirectToMainDomain('header_mismatch') } if (!config.public.customDomainsEnabled) { // If custom domain not allowed, redirect - return redirectToMainDomain() + return redirectToMainDomain('custom_domains_disabled') } if (!customDomainAllowedRoutes.includes(to.name)) { // Custom domain only allowed for form url - return redirectToMainDomain() + return redirectToMainDomain('route_not_allowed') } })