Fix sentry nuxt and custom domain redirect

This commit is contained in:
Julien Nahum
2024-01-12 17:32:10 +01:00
parent b29cdf8d8a
commit be43c5cae3
4 changed files with 14 additions and 18 deletions

8
client/lib/utils.js vendored
View File

@@ -47,7 +47,7 @@ export const appUrl = (path = '/') => {
*/
export const getHost = function () {
if (process.server) {
return useNuxtApp().ssrContext?.event.context.siteConfigNitroOrigin || useNuxtApp().ssrContext?.event.node.req.headers.host
return getDomain(useNuxtApp().ssrContext?.event.context.siteConfigNitroOrigin) || useNuxtApp().ssrContext?.event.node.req.headers.host
} else {
return window.location.host
}
@@ -59,6 +59,7 @@ export const getHost = function () {
* @returns {*}
*/
export const getDomain = function (url) {
if (url.includes('localhost')) return 'localhost'
return (new URL(url)).hostname
}
@@ -68,7 +69,8 @@ export const getDomain = function (url) {
*/
export const customDomainUsed = function() {
const config = useRuntimeConfig()
const appUrl = config.public.appUrl
const appDomain = getDomain(config.public.appUrl)
const host = getHost()
return getDomain(getHost()) !== getDomain(appUrl)
return host !== appDomain && getDomain(host) !== appDomain
}