Files
car-crushers-portal/functions/api/st.ts
Regalijan 8e34e2ce24
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 54s
Test, Build, Deploy / Create Sentry Release (push) Successful in 7s
Send back response from sentry through tunnel
2026-03-14 01:47:42 -04:00

36 lines
977 B
TypeScript

import { jsonError } from "../common.js";
export async function onRequestPost(context: RequestContext) {
const clonedRequest = context.request.clone();
const header = (await context.request.text()).split("\n").at(0);
if (!header) return jsonError("Failed to parse envelope header", 500);
const { dsn } = JSON.parse(header);
if (context.env.REMIX_DSN !== dsn) return jsonError("Bad or no DSN", 400);
const sentryUrl = new URL(dsn);
const resp = await fetch(
`https://${sentryUrl.host}/api${sentryUrl.pathname}/envelope`,
{
body: clonedRequest.body,
headers: {
"content-type": "application/x-sentry-envelope",
"x-forwarded-for": context.request.headers.get(
"cf-connecting-ip",
) as string,
},
method: "POST",
},
);
return new Response(await resp.text(), {
headers: {
"content-type": resp.headers.get("content-type") || "text/plain",
},
status: resp.status,
});
}