From ccad8bf22b190cb78257f8e48a41ff5eaa2a82c3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 15 Jan 2023 14:10:20 +0000 Subject: [PATCH] fix: catch more bots with redirects (#1174) --- plugins/social.server.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/social.server.ts b/plugins/social.server.ts index bae26169..d4f354ee 100644 --- a/plugins/social.server.ts +++ b/plugins/social.server.ts @@ -1,5 +1,7 @@ import { sendRedirect } from 'h3' +const BOT_RE = /bot\b|index|spider|facebookexternalhit|crawl|wget|slurp|mediapartners-google/i + export default defineNuxtPlugin(async (nuxtApp) => { const route = useRoute() if (!route.params.server) @@ -10,7 +12,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { if (!userAgent) return - const isOpenGraphCrawler = /twitterbot|discordbot|facebookexternalhit|googlebot|msnbot|baidu|ahrefsbot/i.test(userAgent) + 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)