chore: cleanup functions

This commit is contained in:
Kieran 2023-03-30 12:54:01 +01:00
parent bf194a8545
commit f5e6ef679b
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 42 additions and 32 deletions

View File

@ -5,21 +5,26 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const id = context.params.id as string;
const next = await context.next();
console.debug(next.status);
console.debug("Fetching data for: ", id);
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
"content-type": "text/plain"
try {
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/e/${id}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
"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"
}
});
}
}
});
console.debug(rsp.status, rsp.statusText);
const body = await rsp.text();
return new Response(body, {
headers: {
"content-type": "text/html"
}
});
} catch {
// ignore
}
return next;
}

View File

@ -5,21 +5,26 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const id = context.params.id as string;
const next = await context.next();
console.debug(next.status);
console.debug("Fetching data for: ", id);
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
"content-type": "text/plain"
try {
const rsp = await fetch(`https://api.snort.social/api/v1/og/tag/p/${id}`, {
method: "POST",
body: await next.arrayBuffer(),
headers: {
"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"
}
});
}
}
});
console.debug(rsp.status, rsp.statusText);
const body = await rsp.text();
return new Response(body, {
headers: {
"content-type": "text/html"
}
});
} catch {
// ignore
}
return next;
}