mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 20:24:18 -04:00
(sentry) use tunnel to circumvent tracker blocking
see: https://docs.sentry.io/platforms/javascript/troubleshooting/, Dealing with Ad-Blockers code inspired from: https://github.com/BLOCKMATERIAL/sentry-tunnel-using-node/blob/main/routes/tunnel.js
This commit is contained in:
parent
d3b54484af
commit
9ce94f8383
@ -242,6 +242,9 @@ const nuxtConfig: NuxtConfig = {
|
||||
return event;
|
||||
},
|
||||
},
|
||||
clientConfig: {
|
||||
tunnel: '/api/sentry/tunnel',
|
||||
},
|
||||
},
|
||||
publicRuntimeConfig: {
|
||||
...config,
|
||||
|
@ -42,6 +42,7 @@ import calendarRoute from './routes/calendar.ts';
|
||||
import translationsRoute from './routes/translations.ts';
|
||||
import subscriptionRoute from './routes/subscription.ts';
|
||||
import discord from './routes/discord.ts';
|
||||
import sentryRoute from './routes/sentry.ts';
|
||||
|
||||
const MemoryStore = memorystore(session);
|
||||
|
||||
@ -60,6 +61,10 @@ app.use(express.json({
|
||||
},
|
||||
}));
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.raw({
|
||||
limit: '10 MB',
|
||||
type: 'text/plain',
|
||||
}));
|
||||
app.use(cookieParser());
|
||||
app.use(session({
|
||||
secret: process.env.SECRET!,
|
||||
@ -179,6 +184,7 @@ app.use(calendarRoute);
|
||||
app.use(translationsRoute);
|
||||
app.use(subscriptionRoute);
|
||||
app.use(discord);
|
||||
app.use(sentryRoute);
|
||||
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
|
30
server/routes/sentry.ts
Normal file
30
server/routes/sentry.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Router } from 'express';
|
||||
|
||||
import { handleErrorAsync } from '~/src/helpers.ts';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post('/sentry/tunnel', handleErrorAsync(async (req, res) => {
|
||||
const envelope = req.body.toString('utf-8');
|
||||
|
||||
const piece = envelope.slice(0, envelope.indexOf('\n'));
|
||||
const header = JSON.parse(piece);
|
||||
|
||||
if (header.dsn !== process.env.SENTRY_DSN) {
|
||||
return res.status(400).send({ message: `Invalid Sentry DSN: ${header.dsn}` });
|
||||
}
|
||||
|
||||
const dsn = new URL(header.dsn);
|
||||
|
||||
const url = `https://${dsn.hostname}/api/${dsn.pathname.substring(1)}/envelope/`;
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: envelope,
|
||||
headers: {
|
||||
'Content-Type': 'application/x-sentry-envelope',
|
||||
},
|
||||
});
|
||||
return res.status(response.status).send(response.body);
|
||||
}));
|
||||
|
||||
export default router;
|
Loading…
x
Reference in New Issue
Block a user