2023-01-14 23:51:12 +00:00
|
|
|
import { sendRedirect } from 'h3'
|
|
|
|
|
|
|
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
|
const route = useRoute()
|
|
|
|
if (!route.params.server)
|
|
|
|
return
|
|
|
|
|
|
|
|
const req = nuxtApp.ssrContext!.event.node.req
|
|
|
|
const userAgent = req.headers['user-agent']!
|
|
|
|
if (!userAgent)
|
|
|
|
return
|
|
|
|
|
2023-01-15 00:47:11 +00:00
|
|
|
const isOpenGraphCrawler = /twitterbot|discordbot|facebookexternalhit|googlebot|msnbot|baidu|ahrefsbot/i.test(userAgent)
|
|
|
|
if (isOpenGraphCrawler) {
|
|
|
|
// Redirect bots to the original instance to respect their social sharing settings
|
2023-01-14 23:51:12 +00:00
|
|
|
await sendRedirect(nuxtApp.ssrContext!.event, `https:/${route.path}`, 301)
|
2023-01-15 00:47:11 +00:00
|
|
|
}
|
2023-01-14 23:51:12 +00:00
|
|
|
})
|