-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathserver.ts
More file actions
39 lines (35 loc) · 1.08 KB
/
server.ts
File metadata and controls
39 lines (35 loc) · 1.08 KB
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
import type { Envelope } from '@sentry/core';
import { parseEnvelope } from '@sentry/core';
import express from 'express';
import type { AddressInfo } from 'net';
/**
* Creates a basic Sentry server that accepts POST to the envelope endpoint
*
* This does no checks on the envelope, it just calls the callback if it managed to parse an envelope from the raw POST
* body data.
*/
export function createBasicSentryServer(onEnvelope: (env: Envelope) => void): Promise<[number, () => void]> {
const app = express();
app.use(express.raw({ type: () => true, inflate: true, limit: '100mb' }));
app.post('/api/:id/envelope/', (req, res) => {
try {
const env = parseEnvelope(req.body as Buffer);
onEnvelope(env);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
res.status(200).send();
});
return new Promise(resolve => {
const server = app.listen(0, () => {
const address = server.address() as AddressInfo;
resolve([
address.port,
() => {
server.close();
},
]);
});
});
}