diff --git a/client/composables/useOpnApi.js b/client/composables/useOpnApi.js index 8eab47e3..eb07807c 100644 --- a/client/composables/useOpnApi.js +++ b/client/composables/useOpnApi.js @@ -67,6 +67,7 @@ export function getOpnRequestsOptions(request, opts) { } } else if (status === 420) { // If invalid domain, redirect to main domain + console.warn("Invalid response from back-end - redirecting to main domain") window.location.href = config.public.appUrl + "?utm_source=failed_custom_domain_redirect" } else if (status >= 500) { diff --git a/client/lib/utils.js b/client/lib/utils.js index 2894334c..bb08978a 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -107,5 +107,13 @@ export const customDomainUsed = function () { const appDomain = getDomain(config.public.appUrl) const host = getHost() + console.log('Checking if custom domain is used', { + appDomain, + host, + getDomain: getDomain(host), + used: host !== appDomain, + hostDomainused: getDomain(host) !== appDomain + }) + return host !== appDomain && getDomain(host) !== appDomain } diff --git a/client/middleware/custom-domain.global.js b/client/middleware/custom-domain.global.js index 3a38118e..d0705cf2 100644 --- a/client/middleware/custom-domain.global.js +++ b/client/middleware/custom-domain.global.js @@ -1,4 +1,4 @@ -import { customDomainUsed, getDomain, getHost } from "~/lib/utils.js" +import {customDomainUsed, getDomain, getHost} from "~/lib/utils.js" /** * Added by Caddy when proxying to the app @@ -13,11 +13,18 @@ const customDomainHeaderName = "user-custom-domain" const customDomainAllowedRoutes = ["forms-slug"] function redirectToMainDomain(details = {}) { - console.warn("Redirecting to main domain", { reason: "unknown", ...details }) + const appDomain = getDomain(config.public.appUrl) + const host = getHost() + console.warn("Redirecting to main domain", { + reason: "unknown", + appDomain, + host, + getDomain: getDomain(host), ...details + }) return navigateTo( useRuntimeConfig().public.appUrl + - "?utm_source=failed_custom_domain_redirect", - { redirectCode: 301, external: true }, + "?utm_source=failed_custom_domain_redirect", + {redirectCode: 301, external: true}, ) } @@ -50,6 +57,7 @@ export default defineNuxtRouteMiddleware((to) => { // Custom domain only allowed for form url return redirectToMainDomain({ reason: "route_not_allowed", + route: to.name }) } })