-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathserver-ignoreOutgoingRequests.js
69 lines (58 loc) · 1.7 KB
/
server-ignoreOutgoingRequests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
const Sentry = require('@sentry/node');
const http = require('http');
Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [
Sentry.httpIntegration({
ignoreOutgoingRequests: (url, request) => {
if (url === 'http://example.com/blockUrl') {
return true;
}
if (request.hostname === 'example.com' && request.path === '/blockRequest') {
return true;
}
return false;
},
}),
],
});
// express must be required after Sentry is initialized
const express = require('express');
const cors = require('cors');
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests');
const app = express();
app.use(cors());
app.get('/testUrl', (_req, response) => {
makeHttpRequest('http://example.com/blockUrl').then(() => {
makeHttpRequest('http://example.com/pass').then(() => {
response.send({ response: 'done' });
});
});
});
app.get('/testRequest', (_req, response) => {
makeHttpRequest('http://example.com/blockRequest').then(() => {
makeHttpRequest('http://example.com/pass').then(() => {
response.send({ response: 'done' });
});
});
});
Sentry.setupExpressErrorHandler(app);
startExpressServerAndSendPortToRunner(app);
function makeHttpRequest(url) {
return new Promise((resolve, reject) => {
http
.get(url, res => {
res.on('data', () => {});
res.on('end', () => {
resolve();
});
})
.on('error', error => {
reject(error);
});
});
}