Skip to content

Commit

Permalink
refactor: Update tunneling to Sentry implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGigi committed Aug 17, 2024
1 parent 17a8cb4 commit 5c46f56
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions src/routes/api/internal/tunnel/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,10 @@ import { PUBLIC_SENTRY_HOST, PUBLIC_SENTRY_PROJECT_ID } from "$env/static/public
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

const SENTRY_PROJECT_IDS = [PUBLIC_SENTRY_PROJECT_ID];

export const POST: RequestHandler = async ({ request, fetch }) => {
try {
const envelopeBytes = await request.arrayBuffer();

const envelope = new TextDecoder().decode(envelopeBytes);

const piece = envelope.split("\n")[0];

const header = JSON.parse(piece);

const dsn = new URL(header["dsn"]);

const projectId = dsn.pathname?.replace("/", "");

if (dsn.hostname !== PUBLIC_SENTRY_HOST) {
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
}

if (!projectId || !SENTRY_PROJECT_IDS.includes(projectId)) {
throw new Error(`Invalid sentry project id: ${projectId}`);
}

const upstream_sentry_url = `https://${PUBLIC_SENTRY_HOST}/api/${projectId}/envelope/`;
const upstream_sentry_url = `https://${PUBLIC_SENTRY_HOST}/api/${PUBLIC_SENTRY_PROJECT_ID}/envelope/`;

await fetch(upstream_sentry_url, {
method: "POST",
Expand Down

0 comments on commit 5c46f56

Please sign in to comment.