Sentry tunneling is broken in their example
This commit is contained in:
parent
bb847974a4
commit
29e9442c2d
1 changed files with 36 additions and 0 deletions
36
packages/website/src/routes/sntry/_server.ts
Normal file
36
packages/website/src/routes/sntry/_server.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
import { SENTRY_HOST, SENTRY_TUNNEL_ALLOWED_IDS } from '$lib/config';
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
try {
|
||||
const envelopeBytes = await request.arrayBuffer();
|
||||
const envelope = new TextDecoder().decode(envelopeBytes);
|
||||
const piece = envelope.split("\n")[0];
|
||||
const header = JSON.parse(piece);
|
||||
// Sometime the DSN header is not set
|
||||
|
||||
const dsn = new URL(header["dsn"]);
|
||||
const project_id = dsn.pathname?.replace("/", "");
|
||||
|
||||
if (dsn.hostname !== SENTRY_HOST) {
|
||||
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
|
||||
}
|
||||
|
||||
if (!project_id || !SENTRY_TUNNEL_ALLOWED_IDS.includes(project_id)) {
|
||||
throw new Error(`Invalid sentry project id: ${project_id}`);
|
||||
}
|
||||
|
||||
const upstream_sentry_url = `https://${SENTRY_HOST}/api/${project_id}/envelope/`;
|
||||
|
||||
await fetch(upstream_sentry_url, {
|
||||
method: "POST",
|
||||
body: envelopeBytes,
|
||||
});
|
||||
|
||||
return json({}, { status: 200 });
|
||||
} catch (e) {
|
||||
console.error("error tunneling to sentry", e);
|
||||
return json({ error: "error tunneling to sentry" }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue