Skip to content

Commit

Permalink
build: add sentry and tunnel function
Browse files Browse the repository at this point in the history
  • Loading branch information
gander committed Jan 26, 2024
1 parent bcdebe9 commit c5fbfe0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
24 changes: 24 additions & 0 deletions functions/bugs-tunnel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export async function onRequestPost({request}) {
let {readable, writable} = new TransformStream();
await request.body.pipeTo(writable);
const [header, body] = readable.tee();
let decoder = new TextDecoder();
let chunk = '';
const headerReader = header.getReader();
while (true) {
const {done, value} = await headerReader.read();
if (done) break;
chunk += decoder.decode(value);
const index = chunk.indexOf('\n');
if (index >= 0) {
const line = chunk.slice(0, index);
const dsn = new URL(JSON.parse(line).dsn);
const headers = request.headers;
headers.set('X-Forwarded-For', request.headers.get('CF-Connecting-IP'));
return fetch(`https://${dsn.host}/api${dsn.pathname}/envelope/`, {
method: 'POST', body, headers,
});
}
}
return new Response(null, {status: 404});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
},
"dependencies": {
"@sentry/vue": "^7.98.0",
"bootstrap": "^5.3.2",
"vue": "^3.4.15"
},
Expand Down
1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface ImportMetaEnv {
readonly VITE_APP_VERSION: string
readonly VITE_UMAMI_ID: string
readonly VITE_UMAMI_SRC: string
readonly VITE_SENTRY_DSN: string;
}

interface ImportMeta {
Expand Down
24 changes: 20 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { createApp } from 'vue'
import 'bootstrap/scss/bootstrap.scss'
import App from './App.vue'
import {createApp} from 'vue';
import 'bootstrap/scss/bootstrap.scss';
import App from './App.vue';
import * as Sentry from '@sentry/vue';

createApp(App).mount('#app')
const app = createApp(App);

if (import.meta.env.PROD && import.meta.env.VITE_SENTRY_DSN) {
Sentry.init({
app,
tunnel: '/bugs-tunnel',
dsn: import.meta.env.VITE_SENTRY_DSN,
environment: import.meta.env.MODE,
integrations: [Sentry.replayIntegration()],
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 1.0,
tracePropagationTargets: ['localhost', 'sentry.gander.pl'],
});
}

app.mount('#app');

0 comments on commit c5fbfe0

Please sign in to comment.