1
- const Sentry = require ( '@sentry/node' ) ;
1
+ import type * as S from '@sentry/node' ;
2
+ const Sentry = require ( '@sentry/node' ) as typeof S ;
2
3
3
4
Sentry . init ( {
4
5
environment : 'qa' , // dynamic sampling bias to keep transactions
@@ -9,38 +10,41 @@ Sentry.init({
9
10
tracePropagationTargets : [ 'http://localhost:3030' , '/external-allowed' ] ,
10
11
} ) ;
11
12
13
+ import type * as H from 'http' ;
14
+ import type * as F from 'fastify' ;
15
+
12
16
// Make sure fastify is imported after Sentry is initialized
13
- const { fastify } = require ( 'fastify' ) ;
14
- const http = require ( 'http' ) ;
17
+ const { fastify } = require ( 'fastify' ) as typeof F ;
18
+ const http = require ( 'http' ) as typeof H ;
15
19
16
20
const app = fastify ( ) ;
17
21
const port = 3030 ;
18
22
const port2 = 3040 ;
19
23
20
24
Sentry . setupFastifyErrorHandler ( app ) ;
21
25
22
- app . get ( '/test-success' , function ( req , res ) {
26
+ app . get ( '/test-success' , function ( _req , res ) {
23
27
res . send ( { version : 'v1' } ) ;
24
28
} ) ;
25
29
26
- app . get ( '/test-param/:param' , function ( req , res ) {
30
+ app . get < { Params : { param : string } } > ( '/test-param/:param' , function ( req , res ) {
27
31
res . send ( { paramWas : req . params . param } ) ;
28
32
} ) ;
29
33
30
- app . get ( '/test-inbound-headers/:id' , function ( req , res ) {
34
+ app . get < { Params : { id : string } } > ( '/test-inbound-headers/:id' , function ( req , res ) {
31
35
const headers = req . headers ;
32
36
33
37
res . send ( { headers, id : req . params . id } ) ;
34
38
} ) ;
35
39
36
- app . get ( '/test-outgoing-http/:id' , async function ( req , res ) {
40
+ app . get < { Params : { id : string } } > ( '/test-outgoing-http/:id' , async function ( req , res ) {
37
41
const id = req . params . id ;
38
42
const data = await makeHttpRequest ( `http://localhost:3030/test-inbound-headers/${ id } ` ) ;
39
43
40
44
res . send ( data ) ;
41
45
} ) ;
42
46
43
- app . get ( '/test-outgoing-fetch/:id' , async function ( req , res ) {
47
+ app . get < { Params : { id : string } } > ( '/test-outgoing-fetch/:id' , async function ( req , res ) {
44
48
const id = req . params . id ;
45
49
const response = await fetch ( `http://localhost:3030/test-inbound-headers/${ id } ` ) ;
46
50
const data = await response . json ( ) ;
@@ -64,7 +68,7 @@ app.get('/test-error', async function (req, res) {
64
68
res . send ( { exceptionId } ) ;
65
69
} ) ;
66
70
67
- app . get ( '/test-exception/:id' , async function ( req , res ) {
71
+ app . get < { Params : { id : string } } > ( '/test-exception/:id' , async function ( req , res ) {
68
72
throw new Error ( `This is an exception with id ${ req . params . id } ` ) ;
69
73
} ) ;
70
74
@@ -110,7 +114,7 @@ app2.get('/external-disallowed', function (req, res) {
110
114
111
115
app2 . listen ( { port : port2 } ) ;
112
116
113
- function makeHttpRequest ( url ) {
117
+ function makeHttpRequest ( url : string ) {
114
118
return new Promise ( resolve => {
115
119
const data : any [ ] = [ ] ;
116
120
0 commit comments