snort/functions/p/[id].ts

31 lines
716 B
TypeScript
Raw Normal View History

2023-03-30 11:18:35 +00:00
interface Env {
}
export const onRequest: PagesFunction<Env> = async (context) => {
const id = context.params.id as string;
const next = await context.next();
2023-03-30 11:54:01 +00:00
try {
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
2023-04-14 09:50:06 +00:00
"user-agent": "Snort-Functions/1.0 (https://snort.social)",
2023-03-30 11:54:01 +00:00
"content-type": "text/plain"
}
});
if (rsp.ok) {
const body = await rsp.text();
if (body.length > 0) {
return new Response(body, {
headers: {
"content-type": "text/html"
}
});
}
2023-03-30 11:18:35 +00:00
}
2023-03-30 11:54:01 +00:00
} catch {
// ignore
}
return next;
2023-03-30 11:18:35 +00:00
}