-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
45 lines (32 loc) · 1.16 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import axios from 'axios';
import express from 'express';
import bodyParser from 'body-parser';
const app = express();
const port = 3005;
app.use(bodyParser.text({ type: ['text/*', '*/json'], limit: '50mb' }))
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.post('/tunnel', async (req, res) => {
try {
const envelope = req.body;
const pieces = envelope.split('\n');
const header = JSON.parse(pieces[0]);
const { host, pathname, username } = new URL(header.dsn);
const projectId = pathname.slice(1);
const url = `https://${host}/api/${projectId}/envelope/?sentry_key=${username}`;
const options = {
'headers': {
'Content-Type': 'application/x-sentry-envelope'
}
};
const response = await axios.post(url, envelope, options);
res.status(201).json({ message: "Success", data: response?.data })
} catch (e) {
const error = e?.response || e?.message;
res.status(400).json({ message: 'invalid request', error: error });
}
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});