mirror of
https://github.com/elk-zone/elk.git
synced 2025-02-16 15:29:47 +03:00
17 lines
523 B
TypeScript
17 lines
523 B
TypeScript
|
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
|
||
|
|
||
|
const isOpenGraphCrawler = /twitterbot|discordbot|facebookexternalhit|googlebot|msnbot|baidu|ahrefsbot|duckduckgo/i.test(userAgent)
|
||
|
if (isOpenGraphCrawler)
|
||
|
await sendRedirect(nuxtApp.ssrContext!.event, `https:/${route.path}`, 301)
|
||
|
})
|