Add more custom domain context

This commit is contained in:
Julien Nahum 2024-01-16 15:31:14 +01:00
parent 359e993374
commit 0fda0c3fbc
1 changed files with 5 additions and 4 deletions

View File

@ -12,7 +12,8 @@ const customDomainHeaderName = 'user-custom-domain'
*/ */
const customDomainAllowedRoutes = ['forms-slug'] 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 }) 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, 'customDomainHeaderValue': customDomainHeaderValue,
'host': getDomain(getHost()), 'host': getDomain(getHost()),
}) })
return redirectToMainDomain() return redirectToMainDomain('header_mismatch')
} }
if (!config.public.customDomainsEnabled) { if (!config.public.customDomainsEnabled) {
// If custom domain not allowed, redirect // If custom domain not allowed, redirect
return redirectToMainDomain() return redirectToMainDomain('custom_domains_disabled')
} }
if (!customDomainAllowedRoutes.includes(to.name)) { if (!customDomainAllowedRoutes.includes(to.name)) {
// Custom domain only allowed for form url // Custom domain only allowed for form url
return redirectToMainDomain() return redirectToMainDomain('route_not_allowed')
} }
}) })