diff --git a/plugins/social.server.ts b/plugins/social.server.ts index a4944475..2a75168c 100644 --- a/plugins/social.server.ts +++ b/plugins/social.server.ts @@ -4,8 +4,17 @@ const BOT_RE = /bot\b|index|spider|facebookexternalhit|crawl|wget|slurp|mediapar export default defineNuxtPlugin(async (nuxtApp) => { const route = useRoute() - if (!('server' in route.params)) - return + + let routePath + if (!route.params['server']) { + const server = nuxtApp.$config.public.defaultServer + if (!server) + return + routePath = `/${server}${route.path}` + } + else { + routePath = route.path + } const userAgent = useRequestHeaders()['user-agent'] if (!userAgent) @@ -14,6 +23,6 @@ export default defineNuxtPlugin(async (nuxtApp) => { const isOpenGraphCrawler = BOT_RE.test(userAgent) if (isOpenGraphCrawler) { // Redirect bots to the original instance to respect their social sharing settings - await sendRedirect(nuxtApp.ssrContext!.event, `https:/${route.path}`, 301) + await sendRedirect(nuxtApp.ssrContext!.event, `https:/${routePath}`, 301) } })