Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Feb 3, 2025
1 parent 7ecd3f7 commit 9db0595
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
19 changes: 1 addition & 18 deletions packages/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const nextConfig = {
source: "/api/public/referents_egalite_professionnelle",
destination: "/api/public/referents_egalite_professionnelle/json",
},
{
source: "/_sentry/:path*",
destination: `${process.env.SENTRY_URL}/api/:path*`,
},
];
},
async headers() {
Expand All @@ -62,19 +58,6 @@ const nextConfig = {
},
],
},
{
source: "/_sentry/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
{
key: "Access-Control-Allow-Headers",
value:
"X-Sentry-Auth,X-CSRF-Token,X-Requested-With,Accept,Accept-Version,Content-Length,Content-MD5,Content-Type,Date,X-Api-Version",
},
],
},
];
},
// Uncomment to debug dsfr script in node_modules with reload / nocache
Expand Down Expand Up @@ -136,7 +119,7 @@ module.exports = withSentryConfig(
transpileClientSDK: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers and CORS issues
tunnelRoute: "/_sentry",
// tunnelRoute: "/_sentry", // Using custom tunnel endpoint instead

// Don't hide source maps from generated client bundles
hideSourceMaps: false,
Expand Down
1 change: 1 addition & 0 deletions packages/app/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const IS_PRODUCTION = ENVIRONMENT === "production";
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
environment: ENVIRONMENT,
tunnel: "/api/monitoring/tunnel",

// Optimal sample rates based on environment
tracesSampleRate: IS_PRODUCTION ? 0.1 : 1.0,
Expand Down
47 changes: 47 additions & 0 deletions packages/app/src/app/api/monitoring/tunnel/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { type NextRequest } from "next/server";

export const dynamic = "force-dynamic";

export async function POST(request: NextRequest) {
const sentryUrl = process.env.SENTRY_URL;
if (!sentryUrl) {
return new Response("Sentry URL not configured", { status: 500 });
}

try {
// Forward the request to Sentry
const sentryResponse = await fetch(`${sentryUrl}/api/34/envelope/`, {
method: "POST",
headers: {
...Object.fromEntries(request.headers),
"Content-Type": "application/x-sentry-envelope",
},
body: await request.text(),
});

// Return the response from Sentry
return new Response(await sentryResponse.text(), {
status: sentryResponse.status,
headers: {
"Content-Type": "application/x-sentry-envelope",
"Access-Control-Allow-Origin": "*",
},
});
} catch (error) {
console.error("Error forwarding to Sentry:", error);
return new Response("Error forwarding to Sentry", { status: 500 });
}
}

// Handle OPTIONS requests for CORS
export async function OPTIONS() {
return new Response(null, {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, X-Sentry-Auth",
"Access-Control-Max-Age": "86400",
},
});
}

0 comments on commit 9db0595

Please sign in to comment.