Add more custom domain context
This commit is contained in:
parent
359e993374
commit
0fda0c3fbc
|
@ -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')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue