@fastify/express 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ test('use a middleware', t => {
18
18
  const instance = fastify()
19
19
  instance.register(expressPlugin)
20
20
  .after(() => {
21
- const useRes = instance.use(function (req, res, next) {
21
+ const useRes = instance.use(function (_req, _res, next) {
22
22
  t.pass('middleware called')
23
23
  next()
24
24
  })
@@ -26,7 +26,7 @@ test('use a middleware', t => {
26
26
  t.equal(useRes, instance)
27
27
  })
28
28
 
29
- instance.get('/', function (request, reply) {
29
+ instance.get('/', function (_request, reply) {
30
30
  reply.send({ hello: 'world' })
31
31
  })
32
32
 
@@ -56,7 +56,7 @@ test('use cors', t => {
56
56
  instance.use(cors())
57
57
  })
58
58
 
59
- instance.get('/', function (request, reply) {
59
+ instance.get('/', function (_request, reply) {
60
60
  reply.send({ hello: 'world' })
61
61
  })
62
62
 
@@ -68,7 +68,7 @@ test('use cors', t => {
68
68
  sget({
69
69
  method: 'GET',
70
70
  url: 'http://localhost:' + instance.server.address().port
71
- }, (err, response, body) => {
71
+ }, (err, response) => {
72
72
  t.error(err)
73
73
  t.equal(response.headers['access-control-allow-origin'], '*')
74
74
  })
@@ -84,7 +84,7 @@ test('use helmet', t => {
84
84
  instance.use(helmet())
85
85
  })
86
86
 
87
- instance.get('/', function (request, reply) {
87
+ instance.get('/', function (_request, reply) {
88
88
  reply.send({ hello: 'world' })
89
89
  })
90
90
 
@@ -96,7 +96,7 @@ test('use helmet', t => {
96
96
  sget({
97
97
  method: 'GET',
98
98
  url: 'http://localhost:' + instance.server.address().port
99
- }, (err, response, body) => {
99
+ }, (err, response) => {
100
100
  t.error(err)
101
101
  t.ok(response.headers['x-xss-protection'])
102
102
  })
@@ -113,7 +113,7 @@ test('use helmet and cors', t => {
113
113
  instance.use(helmet())
114
114
  })
115
115
 
116
- instance.get('/', function (request, reply) {
116
+ instance.get('/', function (_request, reply) {
117
117
  reply.send({ hello: 'world' })
118
118
  })
119
119
 
@@ -125,7 +125,7 @@ test('use helmet and cors', t => {
125
125
  sget({
126
126
  method: 'GET',
127
127
  url: 'http://localhost:' + instance.server.address().port
128
- }, (err, response, body) => {
128
+ }, (err, response) => {
129
129
  t.error(err)
130
130
  t.ok(response.headers['x-xss-protection'])
131
131
  t.equal(response.headers['access-control-allow-origin'], '*')
@@ -139,23 +139,23 @@ test('middlewares with prefix', t => {
139
139
  const instance = fastify()
140
140
  instance.register(expressPlugin)
141
141
  .after(() => {
142
- instance.use(function (req, res, next) {
142
+ instance.use(function (req, _res, next) {
143
143
  req.global = true
144
144
  next()
145
145
  })
146
- instance.use('', function (req, res, next) {
146
+ instance.use('', function (req, _res, next) {
147
147
  req.global2 = true
148
148
  next()
149
149
  })
150
- instance.use('/', function (req, res, next) {
150
+ instance.use('/', function (req, _res, next) {
151
151
  req.root = true
152
152
  next()
153
153
  })
154
- instance.use('/prefix', function (req, res, next) {
154
+ instance.use('/prefix', function (req, _res, next) {
155
155
  req.prefixed = true
156
156
  next()
157
157
  })
158
- instance.use('/prefix/', function (req, res, next) {
158
+ instance.use('/prefix/', function (req, _res, next) {
159
159
  req.slashed = true
160
160
  next()
161
161
  })
@@ -186,7 +186,7 @@ test('middlewares with prefix', t => {
186
186
  method: 'GET',
187
187
  url: 'http://localhost:' + instance.server.address().port + '/',
188
188
  json: true
189
- }, (err, response, body) => {
189
+ }, (err, _response, body) => {
190
190
  t.error(err)
191
191
  t.same(body, {
192
192
  global: true,
@@ -202,7 +202,7 @@ test('middlewares with prefix', t => {
202
202
  method: 'GET',
203
203
  url: 'http://localhost:' + instance.server.address().port + '/prefix',
204
204
  json: true
205
- }, (err, response, body) => {
205
+ }, (err, _response, body) => {
206
206
  t.error(err)
207
207
  t.same(body, {
208
208
  prefixed: true,
@@ -220,7 +220,7 @@ test('middlewares with prefix', t => {
220
220
  method: 'GET',
221
221
  url: 'http://localhost:' + instance.server.address().port + '/prefix/',
222
222
  json: true
223
- }, (err, response, body) => {
223
+ }, (err, _response, body) => {
224
224
  t.error(err)
225
225
  t.same(body, {
226
226
  prefixed: true,
@@ -238,7 +238,7 @@ test('middlewares with prefix', t => {
238
238
  method: 'GET',
239
239
  url: 'http://localhost:' + instance.server.address().port + '/prefix/inner',
240
240
  json: true
241
- }, (err, response, body) => {
241
+ }, (err, _response, body) => {
242
242
  t.error(err)
243
243
  t.same(body, {
244
244
  prefixed: true,
@@ -259,35 +259,35 @@ test('res.end should block middleware execution', t => {
259
259
  t.teardown(instance.close)
260
260
  instance.register(expressPlugin)
261
261
  .after(() => {
262
- instance.use(function (req, res, next) {
262
+ instance.use(function (_req, res) {
263
263
  res.send('hello')
264
264
  })
265
265
 
266
- instance.use(function (req, res, next) {
266
+ instance.use(function () {
267
267
  t.fail('we should not be here')
268
268
  })
269
269
  })
270
270
 
271
- instance.addHook('onRequest', (req, res, next) => {
271
+ instance.addHook('onRequest', (_req, _res, next) => {
272
272
  t.ok('called')
273
273
  next()
274
274
  })
275
275
 
276
- instance.addHook('preHandler', (req, reply, next) => {
276
+ instance.addHook('preHandler', () => {
277
277
  t.fail('this should not be called')
278
278
  })
279
279
 
280
- instance.addHook('onSend', (req, reply, payload, next) => {
280
+ instance.addHook('onSend', (_req, _reply, payload, next) => {
281
281
  t.ok('called')
282
282
  next(null, payload)
283
283
  })
284
284
 
285
- instance.addHook('onResponse', (request, reply, next) => {
285
+ instance.addHook('onResponse', (_request, _reply, next) => {
286
286
  t.ok('called')
287
287
  next()
288
288
  })
289
289
 
290
- instance.get('/', function (request, reply) {
290
+ instance.get('/', function () {
291
291
  t.fail('we should no be here')
292
292
  })
293
293
 
@@ -310,21 +310,21 @@ test('Use a middleware inside a plugin after an encapsulated plugin', t => {
310
310
  t.teardown(f.close)
311
311
  f.register(expressPlugin)
312
312
 
313
- f.register(function (instance, opts, next) {
314
- instance.use(function (req, res, next) {
313
+ f.register(function (instance, _opts, next) {
314
+ instance.use(function (_req, _res, next) {
315
315
  t.ok('first middleware called')
316
316
  next()
317
317
  })
318
318
 
319
- instance.get('/', function (request, reply) {
319
+ instance.get('/', function (_request, reply) {
320
320
  reply.send({ hello: 'world' })
321
321
  })
322
322
 
323
323
  next()
324
324
  })
325
325
 
326
- f.register(fp(function (instance, opts, next) {
327
- instance.use(function (req, res, next) {
326
+ f.register(fp(function (instance, _opts, next) {
327
+ instance.use(function (_req, _res, next) {
328
328
  t.ok('second middleware called')
329
329
  next()
330
330
  })
@@ -351,15 +351,15 @@ test('middlewares should run in the order in which they are defined', t => {
351
351
  t.teardown(f.close)
352
352
  f.register(expressPlugin)
353
353
 
354
- f.register(fp(function (instance, opts, next) {
355
- instance.use(function (req, res, next) {
354
+ f.register(fp(function (instance, _opts, next) {
355
+ instance.use(function (req, _res, next) {
356
356
  t.equal(req.previous, undefined)
357
357
  req.previous = 1
358
358
  next()
359
359
  })
360
360
 
361
- instance.register(fp(function (i, opts, next) {
362
- i.use(function (req, res, next) {
361
+ instance.register(fp(function (i, _opts, next) {
362
+ i.use(function (req, _res, next) {
363
363
  t.equal(req.previous, 2)
364
364
  req.previous = 3
365
365
  next()
@@ -367,7 +367,7 @@ test('middlewares should run in the order in which they are defined', t => {
367
367
  next()
368
368
  }))
369
369
 
370
- instance.use(function (req, res, next) {
370
+ instance.use(function (req, _res, next) {
371
371
  t.equal(req.previous, 1)
372
372
  req.previous = 2
373
373
  next()
@@ -376,8 +376,8 @@ test('middlewares should run in the order in which they are defined', t => {
376
376
  next()
377
377
  }))
378
378
 
379
- f.register(function (instance, opts, next) {
380
- instance.use(function (req, res, next) {
379
+ f.register(function (instance, _opts, next) {
380
+ instance.use(function (req, _res, next) {
381
381
  t.equal(req.previous, 3)
382
382
  req.previous = 4
383
383
  next()
@@ -388,8 +388,8 @@ test('middlewares should run in the order in which they are defined', t => {
388
388
  reply.send({ hello: 'world' })
389
389
  })
390
390
 
391
- instance.register(fp(function (i, opts, next) {
392
- i.use(function (req, res, next) {
391
+ instance.register(fp(function (i, _opts, next) {
392
+ i.use(function (req, _res, next) {
393
393
  t.equal(req.previous, 4)
394
394
  req.previous = 5
395
395
  next()
package/types/index.d.ts CHANGED
@@ -18,7 +18,7 @@ declare module 'fastify' {
18
18
  type FastifyExpress = FastifyPluginCallback<fastifyExpress.FastifyExpressOptions>
19
19
 
20
20
  declare namespace fastifyExpress {
21
-
21
+
22
22
  export interface FastifyExpressOptions {
23
23
  expressHook?: string;
24
24
  createProxyHandler?: (fastifyReq: FastifyRequest) => ProxyHandler<Request>
@@ -28,5 +28,5 @@ declare namespace fastifyExpress {
28
28
  export { fastifyExpress as default }
29
29
  }
30
30
 
31
- declare function fastifyExpress(...params: Parameters<FastifyExpress>): ReturnType<FastifyExpress>
31
+ declare function fastifyExpress (...params: Parameters<FastifyExpress>): ReturnType<FastifyExpress>
32
32
  export = fastifyExpress
@@ -1,6 +1,6 @@
1
1
  import Fastify, { FastifyRequest } from 'fastify'
2
2
  import fastifyExpress from '..'
3
- import { expectType } from "tsd"
3
+ import { expectType } from 'tsd'
4
4
  import { Application } from 'express'
5
5
 
6
6
  const app = Fastify()
@@ -9,7 +9,7 @@ app.register(fastifyExpress)
9
9
  app.register(fastifyExpress, {
10
10
  expressHook: 'onRequest',
11
11
  createProxyHandler: (fastifyReq) => ({
12
- set(target, prop, value) {
12
+ set (target, prop, value) {
13
13
  expectType<FastifyRequest>(fastifyReq)
14
14
  return Reflect.set(target, prop, value)
15
15
  }
@@ -22,4 +22,4 @@ app.express.disable('x-powered-by')
22
22
 
23
23
  app.use('/world', (_req, res) => {
24
24
  res.sendStatus(200)
25
- })
25
+ })