fix: catch more bots with redirects (#1174)
This commit is contained in:
parent
18ad1c2333
commit
ccad8bf22b
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue