Skip to content

Commit

Permalink
feat: implement social previews by redirecting to origin server (elk-…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jan 14, 2023
1 parent a8e1cb8 commit d46ddbe
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/social.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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)
})

0 comments on commit d46ddbe

Please sign in to comment.