Skip to content

Commit 01c4ff8

Browse files
committed
adjust fastify types
1 parent ebf6591 commit 01c4ff8

File tree

1 file changed

+14
-10
lines changed
  • dev-packages/e2e-tests/test-applications/node-fastify-app/src

1 file changed

+14
-10
lines changed

dev-packages/e2e-tests/test-applications/node-fastify-app/src/app.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const Sentry = require('@sentry/node');
1+
import type * as S from '@sentry/node';
2+
const Sentry = require('@sentry/node') as typeof S;
23

34
Sentry.init({
45
environment: 'qa', // dynamic sampling bias to keep transactions
@@ -9,38 +10,41 @@ Sentry.init({
910
tracePropagationTargets: ['http://localhost:3030', '/external-allowed'],
1011
});
1112

13+
import type * as H from 'http';
14+
import type * as F from 'fastify';
15+
1216
// 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;
1519

1620
const app = fastify();
1721
const port = 3030;
1822
const port2 = 3040;
1923

2024
Sentry.setupFastifyErrorHandler(app);
2125

22-
app.get('/test-success', function (req, res) {
26+
app.get('/test-success', function (_req, res) {
2327
res.send({ version: 'v1' });
2428
});
2529

26-
app.get('/test-param/:param', function (req, res) {
30+
app.get<{ Params: { param: string } }>('/test-param/:param', function (req, res) {
2731
res.send({ paramWas: req.params.param });
2832
});
2933

30-
app.get('/test-inbound-headers/:id', function (req, res) {
34+
app.get<{ Params: { id: string } }>('/test-inbound-headers/:id', function (req, res) {
3135
const headers = req.headers;
3236

3337
res.send({ headers, id: req.params.id });
3438
});
3539

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) {
3741
const id = req.params.id;
3842
const data = await makeHttpRequest(`http://localhost:3030/test-inbound-headers/${id}`);
3943

4044
res.send(data);
4145
});
4246

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) {
4448
const id = req.params.id;
4549
const response = await fetch(`http://localhost:3030/test-inbound-headers/${id}`);
4650
const data = await response.json();
@@ -64,7 +68,7 @@ app.get('/test-error', async function (req, res) {
6468
res.send({ exceptionId });
6569
});
6670

67-
app.get('/test-exception/:id', async function (req, res) {
71+
app.get<{ Params: { id: string } }>('/test-exception/:id', async function (req, res) {
6872
throw new Error(`This is an exception with id ${req.params.id}`);
6973
});
7074

@@ -110,7 +114,7 @@ app2.get('/external-disallowed', function (req, res) {
110114

111115
app2.listen({ port: port2 });
112116

113-
function makeHttpRequest(url) {
117+
function makeHttpRequest(url: string) {
114118
return new Promise(resolve => {
115119
const data: any[] = [];
116120

0 commit comments

Comments
 (0)