Skip to content

Commit

Permalink
Fix user-agent header in SSR OpenGraph routes
Browse files Browse the repository at this point in the history
  • Loading branch information
preschian committed Nov 11, 2023
1 parent 585e9de commit 8c80142
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ssr-opengraph/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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(<Opengraph {...props} />);
Expand Down

0 comments on commit 8c80142

Please sign in to comment.