fix: catch more bots with redirects (#1174)
This commit is contained in:
parent
18ad1c2333
commit
ccad8bf22b
|
@ -1,5 +1,7 @@
|
||||||
import { sendRedirect } from 'h3'
|
import { sendRedirect } from 'h3'
|
||||||
|
|
||||||
|
const BOT_RE = /bot\b|index|spider|facebookexternalhit|crawl|wget|slurp|mediapartners-google/i
|
||||||
|
|
||||||
export default defineNuxtPlugin(async (nuxtApp) => {
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
if (!route.params.server)
|
if (!route.params.server)
|
||||||
|
@ -10,7 +12,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
||||||
if (!userAgent)
|
if (!userAgent)
|
||||||
return
|
return
|
||||||
|
|
||||||
const isOpenGraphCrawler = /twitterbot|discordbot|facebookexternalhit|googlebot|msnbot|baidu|ahrefsbot/i.test(userAgent)
|
const isOpenGraphCrawler = BOT_RE.test(userAgent)
|
||||||
if (isOpenGraphCrawler) {
|
if (isOpenGraphCrawler) {
|
||||||
// Redirect bots to the original instance to respect their social sharing settings
|
// 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:/${route.path}`, 301)
|
||||||
|
|
Loading…
Reference in a new issue