Skip to content

Commit 0a07399

Browse files
authored
Add javascript example for tunnel endpoint (#9080)
Additional configuration for javascript servers. A simple POST endpoint parsing Sentry browser events and redirect them to Sentry
1 parent 1bc12d2 commit 0a07399

File tree

1 file changed

+31
-0
lines changed
  • docs/platforms/javascript/common/troubleshooting

1 file changed

+31
-0
lines changed

docs/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,37 @@ class HomeController < ApplicationController
195195
end
196196
```
197197

198+
```javascript
199+
const SENTRY_HOST = "oXXXXXX.ingest.sentry.io"
200+
const SENTRY_PROJECT_IDS = ["123456"]
201+
202+
export const postAction = async ({ request }) => {
203+
try {
204+
const envelope = await request.text();
205+
const piece = envelope.split("\n")[0];
206+
const header = JSON.parse(piece);
207+
const dsn = new URL(header["dsn"]);
208+
const project_id = dsn.pathname?.replace("/", "");
209+
210+
if (dsn.hostname !== SENTRY_HOST) {
211+
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
212+
}
213+
214+
if (!project_id || !SENTRY_PROJECT_IDS.includes(project_id)) {
215+
throw new Error(`Invalid sentry project id: ${project_id}`);
216+
}
217+
218+
const upstream_sentry_url = `https://${SENTRY_HOST}/api/${project_id}/envelope/`;
219+
await fetch(upstream_sentry_url, { method: "POST", body: envelope });
220+
221+
return json({}, { status: 200 });
222+
} catch (e) {
223+
console.error("error tunneling to sentry", e);
224+
return json({ error: "error tunneling to sentry" }, { status: 500 });
225+
}
226+
};
227+
```
228+
198229
If your use-case is related to the SDK package itself being blocked, any of the following solutions will help you resolve this issue.
199230
200231
### Using the NPM Package

0 commit comments

Comments
 (0)