fix: add proxy for open graph

feat/profile-og
Arik Chakma 7 months ago
parent 6dc9579ffa
commit fe21075d63
  1. 1
      src/api/api.ts
  2. 45
      src/pages/og/[slug].ts
  3. 3
      src/pages/u/[username].astro

@ -1,4 +1,3 @@
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../lib/jwt.ts';
import type { APIContext } from 'astro';

@ -0,0 +1,45 @@
import type { APIRoute } from 'astro';
export const prerender = false;
type Params = {
slug: string;
};
export const GET: APIRoute<any, Params> = async (context) => {
const { slug } = context.params;
if (!slug.startsWith('user-')) {
return new Response(
JSON.stringify({
error: 'Invalid slug',
}),
{
status: 400,
},
);
}
const username = slug.replace('user-', '');
if (!username) {
return new Response(
JSON.stringify({
error: 'Invalid username',
}),
{
status: 400,
},
);
}
const response = await fetch(
`${import.meta.env.PUBLIC_API_URL}/v1-profile-open-graph/${username}`,
);
const svg = await response.text();
return new Response(svg, {
headers: {
'Content-Type': 'image/svg+xml',
},
});
};

@ -23,7 +23,8 @@ if (error || !userDetails) {
errorMessage = error?.message || 'User not found';
}
const ogImage = `${import.meta.env.PUBLIC_API_URL}/v1-profile-open-graph/${username}`;
const origin = Astro.url.origin;
const ogImage = `${origin}/og/user-${username}`;
---
<BaseLayout

Loading…
Cancel
Save