@fastify/express 2.3.0 → 4.0.0-pre.fv5.1
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.
- package/.gitattributes +2 -0
- package/.github/workflows/ci.yml +6 -1
- package/README.md +2 -2
- package/index.js +7 -1
- package/package.json +18 -14
- package/test/basic.test.js +4 -3
- package/test/hooks.test.js +35 -0
- package/test/middleware.test.js +3 -2
- package/.taprc +0 -1
package/.gitattributes
ADDED
package/.github/workflows/ci.yml
CHANGED
|
@@ -2,6 +2,11 @@ name: CI
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
- next
|
|
9
|
+
- 'v*'
|
|
5
10
|
paths-ignore:
|
|
6
11
|
- 'docs/**'
|
|
7
12
|
- '*.md'
|
|
@@ -12,7 +17,7 @@ on:
|
|
|
12
17
|
|
|
13
18
|
jobs:
|
|
14
19
|
test:
|
|
15
|
-
uses: fastify/workflows/.github/workflows/plugins-ci.yml@
|
|
20
|
+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
|
|
16
21
|
with:
|
|
17
22
|
lint: true
|
|
18
23
|
license-check: true
|
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ async function subsystem (fastify, opts) {
|
|
|
143
143
|
### Hooks and middlewares
|
|
144
144
|
|
|
145
145
|
Every registered middleware will be run during the `onRequest` hook phase, so the registration order is important.
|
|
146
|
-
Take a look at the [Lifecycle](https://
|
|
146
|
+
Take a look at the [Lifecycle](https://fastify.dev/docs/latest/Reference/Lifecycle) documentation page to understand better how every request is executed.
|
|
147
147
|
|
|
148
148
|
```js
|
|
149
149
|
const fastify = require('fastify')()
|
|
@@ -174,7 +174,7 @@ If you need to run a middleware only under certain path(s), just pass the path a
|
|
|
174
174
|
|
|
175
175
|
```js
|
|
176
176
|
const fastify = require('fastify')()
|
|
177
|
-
const path = require('path')
|
|
177
|
+
const path = require('node:path')
|
|
178
178
|
const serveStatic = require('serve-static')
|
|
179
179
|
|
|
180
180
|
fastify
|
package/index.js
CHANGED
|
@@ -40,13 +40,19 @@ function fastifyExpress (fastify, options, next) {
|
|
|
40
40
|
req.raw = new Proxy(req.raw, createProxyHandler(req))
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
const { url } = req.raw
|
|
44
|
+
req.raw.originalUrl = url
|
|
44
45
|
req.raw.id = req.id
|
|
45
46
|
req.raw.hostname = req.hostname
|
|
46
47
|
req.raw.ip = req.ip
|
|
47
48
|
req.raw.ips = req.ips
|
|
48
49
|
req.raw.log = req.log
|
|
49
50
|
reply.raw.log = req.log
|
|
51
|
+
reply.raw.send = function send (...args) {
|
|
52
|
+
// Restore req.raw.url to its original value https://github.com/fastify/fastify-express/issues/11
|
|
53
|
+
req.raw.url = url
|
|
54
|
+
return reply.send.apply(reply, args)
|
|
55
|
+
}
|
|
50
56
|
|
|
51
57
|
// backward compatibility for body-parser
|
|
52
58
|
if (req.body) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-pre.fv5.1",
|
|
4
4
|
"description": "Express compatibility layer for Fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"types": "types/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"lint": "standard",
|
|
@@ -28,29 +29,32 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/fastify/fastify-express#readme",
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@fastify/formbody": "^
|
|
32
|
-
"@types/express": "^4.17.
|
|
32
|
+
"@fastify/formbody": "^8.0.0-pre.fv5.2",
|
|
33
|
+
"@types/express": "^4.17.21",
|
|
33
34
|
"@types/node": "*",
|
|
34
|
-
"body-parser": "^1.20.
|
|
35
|
+
"body-parser": "^1.20.2",
|
|
35
36
|
"cors": "^2.8.5",
|
|
36
|
-
"fastify": "^
|
|
37
|
-
"helmet": "^
|
|
38
|
-
"passport": "^0.
|
|
37
|
+
"fastify": "^5.0.0-alpha.3",
|
|
38
|
+
"helmet": "^7.1.0",
|
|
39
|
+
"passport": "^0.7.0",
|
|
39
40
|
"passport-http-bearer": "^1.0.1",
|
|
40
|
-
"serve-static": "^1.
|
|
41
|
-
"simple-get": "^4.0.
|
|
42
|
-
"standard": "^17.
|
|
43
|
-
"tap": "^
|
|
44
|
-
"tsd": "^0.
|
|
41
|
+
"serve-static": "^1.15.0",
|
|
42
|
+
"simple-get": "^4.0.1",
|
|
43
|
+
"standard": "^17.1.0",
|
|
44
|
+
"tap": "^18.7.1",
|
|
45
|
+
"tsd": "^0.31.0"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"express": "^4.
|
|
48
|
-
"fastify-plugin": "^
|
|
48
|
+
"express": "^4.18.3",
|
|
49
|
+
"fastify-plugin": "^5.0.0-pre.fv5.1"
|
|
49
50
|
},
|
|
50
51
|
"tsd": {
|
|
51
52
|
"directory": "test/types"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|
|
54
55
|
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"tap": {
|
|
58
|
+
"disable-coverage": true
|
|
55
59
|
}
|
|
56
60
|
}
|
package/test/basic.test.js
CHANGED
|
@@ -578,7 +578,7 @@ test('Middleware chain (with errors) / 2', t => {
|
|
|
578
578
|
})
|
|
579
579
|
|
|
580
580
|
test('Send a response from a middleware', t => {
|
|
581
|
-
t.plan(
|
|
581
|
+
t.plan(5)
|
|
582
582
|
|
|
583
583
|
const fastify = Fastify()
|
|
584
584
|
|
|
@@ -602,8 +602,9 @@ test('Send a response from a middleware', t => {
|
|
|
602
602
|
t.fail('We should not be here')
|
|
603
603
|
})
|
|
604
604
|
|
|
605
|
-
fastify.addHook('onSend', (req, reply, next) => {
|
|
606
|
-
t.
|
|
605
|
+
fastify.addHook('onSend', (req, reply, payload, next) => {
|
|
606
|
+
t.ok('called')
|
|
607
|
+
next(null, payload)
|
|
607
608
|
})
|
|
608
609
|
|
|
609
610
|
fastify.addHook('onResponse', (req, reply, next) => {
|
package/test/hooks.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const express = require('express')
|
|
5
6
|
const expressPlugin = require('../index')
|
|
6
7
|
|
|
7
8
|
test('onSend hook should receive valid request and reply objects if middleware fails', t => {
|
|
@@ -35,3 +36,37 @@ test('onSend hook should receive valid request and reply objects if middleware f
|
|
|
35
36
|
t.equal(res.statusCode, 500)
|
|
36
37
|
})
|
|
37
38
|
})
|
|
39
|
+
|
|
40
|
+
test('request.url is not mutated between onRequest and onResponse', t => {
|
|
41
|
+
t.plan(4)
|
|
42
|
+
const fastify = Fastify()
|
|
43
|
+
const targetUrl = '/hubba/bubba'
|
|
44
|
+
|
|
45
|
+
fastify.addHook('onRequest', (request, _, next) => {
|
|
46
|
+
t.equal(request.url, targetUrl)
|
|
47
|
+
next()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
fastify.addHook('onResponse', (request, _, next) => {
|
|
51
|
+
t.equal(request.url, targetUrl)
|
|
52
|
+
next()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
fastify.register(expressPlugin).after(() => {
|
|
56
|
+
const mainRouter = express.Router()
|
|
57
|
+
const innerRouter = express.Router()
|
|
58
|
+
mainRouter.use('/hubba', innerRouter)
|
|
59
|
+
innerRouter.get('/bubba', (req, res) => {
|
|
60
|
+
res.sendStatus(200)
|
|
61
|
+
})
|
|
62
|
+
fastify.use(mainRouter)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
fastify.inject({
|
|
66
|
+
method: 'GET',
|
|
67
|
+
url: targetUrl
|
|
68
|
+
}, (err, res) => {
|
|
69
|
+
t.error(err)
|
|
70
|
+
t.equal(res.statusCode, 200)
|
|
71
|
+
})
|
|
72
|
+
})
|
package/test/middleware.test.js
CHANGED
|
@@ -253,7 +253,7 @@ test('middlewares with prefix', t => {
|
|
|
253
253
|
})
|
|
254
254
|
|
|
255
255
|
test('res.end should block middleware execution', t => {
|
|
256
|
-
t.plan(
|
|
256
|
+
t.plan(6)
|
|
257
257
|
|
|
258
258
|
const instance = fastify()
|
|
259
259
|
t.teardown(instance.close)
|
|
@@ -278,7 +278,8 @@ test('res.end should block middleware execution', t => {
|
|
|
278
278
|
})
|
|
279
279
|
|
|
280
280
|
instance.addHook('onSend', (req, reply, payload, next) => {
|
|
281
|
-
t.
|
|
281
|
+
t.ok('called')
|
|
282
|
+
next(null, payload)
|
|
282
283
|
})
|
|
283
284
|
|
|
284
285
|
instance.addHook('onResponse', (request, reply, next) => {
|
package/.taprc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--no-coverage
|