From 8c801423fdd3a00bbf278ec882bcb9a4b79765e3 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Sat, 11 Nov 2023 19:23:01 +0700 Subject: [PATCH] Fix user-agent header in SSR OpenGraph routes --- ssr-opengraph/src/index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ssr-opengraph/src/index.tsx b/ssr-opengraph/src/index.tsx index 089f540..4aa6e63 100644 --- a/ssr-opengraph/src/index.tsx +++ b/ssr-opengraph/src/index.tsx @@ -9,7 +9,7 @@ const app = new Hono(); const chains = ['bsx', 'snek', 'rmrk', 'ksm', 'ahp', 'ahk']; app.get('/', async(c) => { - const useragent = c.req.headers.get('user-agent'); + const useragent = c.req.header('User-Agent') if (useragent && !isbot(useragent)) { return fetch(c.req.url); @@ -29,7 +29,7 @@ app.get('/', async(c) => { }) app.get('/:chain/:type/:id/*', async (c) => { - const useragent = c.req.headers.get('user-agent'); + const useragent = c.req.header('User-Agent') if (useragent && !isbot(useragent)) { return fetch(c.req.url); @@ -40,6 +40,19 @@ app.get('/:chain/:type/:id/*', async (c) => { const type = c.req.param('type'); if (chains.includes(chain)) { + if (type === 'collection' && chain === 'ahk') { + const url = new URL (c.req.url); + const { pathname, search } = url; + const opengraph = `https://nuxt-opengraph.kodadot.workers.dev/${pathname}${search}` + + const headers = new Headers(c.req.raw.headers); + const request = new Request(opengraph, { + headers + }) + + return await fetch(request) + } + if (type === 'gallery' || type === 'detail') { const props = await galleryDetail(chain, id); return c.html();