Global custom domainmiddleware client as well

This commit is contained in:
Julien Nahum 2024-01-16 11:33:38 +01:00
parent b19baaf8f3
commit b25bc8bca8
1 changed files with 2 additions and 6 deletions

View File

@ -17,18 +17,14 @@ function redirectToMainDomain() {
} }
export default defineNuxtRouteMiddleware((to, from) => { export default defineNuxtRouteMiddleware((to, from) => {
if (process.client) return if (!customDomainUsed()) return
const config = useRuntimeConfig() const config = useRuntimeConfig()
if (!customDomainUsed()) return
console.info('loadedConfig',useRuntimeConfig())
console.log(useRequestHeaders(),customDomainHeaderName)
const customDomainHeaderValue = useRequestHeaders()[customDomainHeaderName] const customDomainHeaderValue = useRequestHeaders()[customDomainHeaderName]
if (!customDomainHeaderValue || customDomainHeaderValue !== getDomain(getHost())) { if (!customDomainHeaderValue || customDomainHeaderValue !== getDomain(getHost())) {
// If custom domain header doesn't match, redirect // If custom domain header doesn't match, redirect
console.info('Custom domain header does not match, redirecting',{ console.error('Custom domain header does not match, redirecting',{
'customDomainHeaderValue': customDomainHeaderValue, 'customDomainHeaderValue': customDomainHeaderValue,
'host': getDomain(getHost()), 'host': getDomain(getHost()),
}) })