@fastify/express 4.0.1 → 4.0.3

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.
@@ -9,5 +9,5 @@ updates:
9
9
  - package-ecosystem: "npm"
10
10
  directory: "/"
11
11
  schedule:
12
- interval: "weekly"
12
+ interval: "monthly"
13
13
  open-pull-requests-limit: 10
@@ -4,7 +4,6 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - main
7
- - master
8
7
  - next
9
8
  - 'v*'
10
9
  paths-ignore:
@@ -15,9 +14,20 @@ on:
15
14
  - 'docs/**'
16
15
  - '*.md'
17
16
 
17
+ # This allows a subsequently queued workflow run to interrupt previous runs
18
+ concurrency:
19
+ group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
20
+ cancel-in-progress: true
21
+
22
+ permissions:
23
+ contents: read
24
+
18
25
  jobs:
19
26
  test:
20
- uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0
27
+ permissions:
28
+ contents: write
29
+ pull-requests: write
30
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
21
31
  with:
22
- lint: true
23
32
  license-check: true
33
+ lint: true
package/LICENSE CHANGED
@@ -1,6 +1,8 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Fastify
3
+ Copyright (c) 2019-present The Fastify team
4
+
5
+ The Fastify team members are listed at https://github.com/fastify/fastify#team.
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
8
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +21,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
21
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
23
  SOFTWARE.
24
+
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @fastify/express
2
2
 
3
- ![CI](https://github.com/fastify/fastify-express/workflows/CI/badge.svg)
3
+ [![CI](https://github.com/fastify/fastify-express/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-express/actions/workflows/ci.yml)
4
4
  [![NPM version](https://img.shields.io/npm/v/@fastify/express.svg?style=flat)](https://www.npmjs.com/package/@fastify/express)
5
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
5
+ [![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
6
6
 
7
7
  This plugin adds full [Express](http://expressjs.com) compatibility to Fastify, it exposes the same `use` function of Express, and it allows you to use any Express middleware or application.<br/>
8
8
 
@@ -13,7 +13,7 @@ This plugin adds full [Express](http://expressjs.com) compatibility to Fastify,
13
13
  <td><b>This plugin should not be used as a long-term solution, it aims to help you have a smooth transition from Express to Fastify, but you should migrate your Express specific code to Fastify over time.</b></td>
14
14
  </tr>
15
15
  <tr>
16
- <td><b>Since <a href="https://github.com/expressjs/express/issues/2761">Express does not support Node.js core HTTP/2 module</a>, this plugin does not support HTTP/2 too.</b></td>
16
+ <td><b>Since <a href="https://github.com/expressjs/express/issues/2761">Express does not support Node.js core HTTP/2 module</a>, this plugin does not support HTTP/2 either.</b></td>
17
17
  </tr>
18
18
  <tbody>
19
19
  </table>
@@ -23,6 +23,19 @@ This plugin adds full [Express](http://expressjs.com) compatibility to Fastify,
23
23
  npm i @fastify/express
24
24
  ```
25
25
 
26
+ ### Compatibility
27
+ | Plugin version | Fastify version |
28
+ | ---------------|-----------------|
29
+ | `>=4.x` | `^5.x` |
30
+ | `>=2.x <4.x` | `^4.x` |
31
+ | `^1.x` | `^3.x` |
32
+ | `^0.x` | `^2.x` |
33
+
34
+
35
+ Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
36
+ in the table above.
37
+ See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.
38
+
26
39
  ## Usage
27
40
  Register the plugin and start using your Express middlewares.
28
41
  ```js
@@ -105,10 +118,10 @@ me@computer ~ % curl -X GET http://localhost:3000/foo
105
118
  {"foo":"bar"}%
106
119
  me@computer ~ % curl -X GET http://localhost:3000/bar
107
120
  {"msg":"not found"}%
108
- me@computer ~ % curl -X PATCH -H 'content-type:application/json' http://localhost:3000/bar
121
+ me@computer ~ % curl -X PATCH -H 'content-type:application/json' http://localhost:3000/bar
109
122
  {"msg":"no req.body"}%
110
123
  me@computer ~ % curl -X PATCH -H 'content-type:application/json' -d '{"foo2":"bar2"}' http://localhost:3000/bar
111
- {"foo2":"bar2"}%
124
+ {"foo2":"bar2"}%
112
125
  ```
113
126
 
114
127
  ### Encapsulation support
@@ -140,9 +153,9 @@ async function subsystem (fastify, opts) {
140
153
  }
141
154
  ```
142
155
 
143
- ### Hooks and middlewares
156
+ ### Hooks and middleware
144
157
 
145
- Every registered middleware will be run during the `onRequest` hook phase, so the registration order is important.
158
+ Every registered middleware will be run during the `onRequest` hook phase, so the registration order is important.
146
159
  Take a look at the [Lifecycle](https://fastify.dev/docs/latest/Reference/Lifecycle) documentation page to understand better how every request is executed.
147
160
 
148
161
  ```js
@@ -170,7 +183,7 @@ async function subsystem (fastify, opts) {
170
183
 
171
184
  ### Restrict middleware execution to a certain path(s)
172
185
 
173
- If you need to run a middleware only under certain path(s), just pass the path as first parameter to use and you are done!
186
+ If you need to run a middleware only under certain path(s), just pass the path as the first parameter to use and you are done!
174
187
 
175
188
  ```js
176
189
  const fastify = require('fastify')()
@@ -197,7 +210,7 @@ async function subsystem (fastify, opts) {
197
210
 
198
211
  It is possible to wrap the Express request object in a Proxy by passing `createProxyHandler` function to generate the Proxy handler. The function will receive the Fastify request object as the first parameter.
199
212
 
200
- For example using Proxy to expose something from Fastify request into the Express request.
213
+ For example, using Proxy to expose something from Fastify request into the Express request.
201
214
 
202
215
  ```js
203
216
  fastify.decorateRequest('welcomeMessage', 'Hello World');
@@ -220,9 +233,9 @@ To use this module with TypeScript, make sure to install `@types/express`.
220
233
 
221
234
  You will need to add `"types": ["@fastify/express"]` to your tsconfig.json file when using `require` to import the plugin.
222
235
 
223
- ## Middlewares alternatives
236
+ ## Middleware alternatives
224
237
 
225
- Fastify offers some alternatives to the most commonly used middlewares, following, you can find a list.
238
+ Fastify offers some alternatives to the most commonly used middleware:
226
239
 
227
240
  | Express Middleware | Fastify Plugin |
228
241
  | ------------- |---------------|
@@ -235,7 +248,7 @@ Fastify offers some alternatives to the most commonly used middlewares, followin
235
248
  ### POST request with body hangs up
236
249
 
237
250
  [body-parser](https://github.com/expressjs/body-parser) library incompatible with `fastify-express`, when you have `fastify` routes and any `express` middlewares.
238
- Any POST requests with **body**, which `body-parser` will try to parse, will be hangs up.
251
+ Any POST requests with **body**, which `body-parser` will try to parse, will hang up.
239
252
 
240
253
  Example application:
241
254
 
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({
4
+ ignores: require('neostandard').resolveIgnoresFromGitignore(),
5
+ ts: true
6
+ })
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fp = require('fastify-plugin')
4
4
  const Express = require('express')
5
+ const FindMyWay = require('find-my-way')
5
6
  const kMiddlewares = Symbol('fastify-express-middlewares')
6
7
 
7
8
  function fastifyExpress (fastify, options, next) {
@@ -41,6 +42,11 @@ function fastifyExpress (fastify, options, next) {
41
42
  }
42
43
 
43
44
  const { url } = req.raw
45
+
46
+ const decodedUrl = FindMyWay.sanitizeUrlPath(url)
47
+ // Decode URL before Express matches middleware to prevent encoded path bypass
48
+ // e.g., /%61dmin should match middleware registered on /admin
49
+ req.raw.url = decodedUrl
44
50
  req.raw.originalUrl = url
45
51
  req.raw.id = req.id
46
52
  req.raw.hostname = req.hostname
@@ -50,7 +56,7 @@ function fastifyExpress (fastify, options, next) {
50
56
  reply.raw.log = req.log
51
57
  reply.raw.send = function send (...args) {
52
58
  // Restore req.raw.url to its original value https://github.com/fastify/fastify-express/issues/11
53
- req.raw.url = url
59
+ req.raw.url = decodedUrl
54
60
  return reply.send.apply(reply, args)
55
61
  }
56
62
 
@@ -59,6 +65,7 @@ function fastifyExpress (fastify, options, next) {
59
65
  req.raw.body = req.body
60
66
  }
61
67
  // backward compatibility for cookie-parser
68
+ /* c8 ignore next 3 */
62
69
  if (req.cookies) {
63
70
  req.raw.cookies = req.cookies
64
71
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@fastify/express",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Express compatibility layer for Fastify",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
7
7
  "types": "types/index.d.ts",
8
8
  "scripts": {
9
- "lint": "standard",
9
+ "lint": "eslint",
10
+ "lint:fix": "eslint --fix",
10
11
  "test": "npm run test:unit && npm run test:typescript",
11
- "test:unit": "tap",
12
+ "test:unit": "c8 --100 --reporter html node --test",
12
13
  "test:typescript": "tsd"
13
14
  },
14
15
  "repository": {
@@ -23,38 +24,65 @@
23
24
  "compatibility"
24
25
  ],
25
26
  "author": "Tomas Della Vedova - @delvedor (http://delved.org)",
27
+ "contributors": [
28
+ {
29
+ "name": "Matteo Collina",
30
+ "email": "hello@matteocollina.com"
31
+ },
32
+ {
33
+ "name": "Manuel Spigolon",
34
+ "email": "behemoth89@gmail.com"
35
+ },
36
+ {
37
+ "name": "James Sumners",
38
+ "url": "https://james.sumners.info"
39
+ },
40
+ {
41
+ "name": "Frazer Smith",
42
+ "email": "frazer.dev@icloud.com",
43
+ "url": "https://github.com/fdawgs"
44
+ }
45
+ ],
26
46
  "license": "MIT",
27
47
  "bugs": {
28
48
  "url": "https://github.com/fastify/fastify-express/issues"
29
49
  },
30
50
  "homepage": "https://github.com/fastify/fastify-express#readme",
51
+ "funding": [
52
+ {
53
+ "type": "github",
54
+ "url": "https://github.com/sponsors/fastify"
55
+ },
56
+ {
57
+ "type": "opencollective",
58
+ "url": "https://opencollective.com/fastify"
59
+ }
60
+ ],
31
61
  "devDependencies": {
32
62
  "@fastify/formbody": "^8.0.0",
33
- "@types/express": "^4.17.21",
63
+ "@types/express": "^5.0.0",
34
64
  "@types/node": "*",
35
65
  "body-parser": "^1.20.2",
66
+ "c8": "^10.1.3",
36
67
  "cors": "^2.8.5",
68
+ "eslint": "^9.17.0",
37
69
  "fastify": "^5.0.0",
38
- "helmet": "^7.1.0",
70
+ "helmet": "^8.0.0",
71
+ "neostandard": "^0.12.0",
39
72
  "passport": "^0.7.0",
40
73
  "passport-http-bearer": "^1.0.1",
41
- "serve-static": "^1.15.0",
42
- "simple-get": "^4.0.1",
43
- "standard": "^17.1.0",
44
- "tap": "^21.0.0",
45
- "tsd": "^0.31.0"
74
+ "serve-static": "^2.2.0",
75
+ "tsd": "^0.33.0"
46
76
  },
47
77
  "dependencies": {
48
78
  "express": "^4.18.3",
49
- "fastify-plugin": "^5.0.0"
79
+ "fastify-plugin": "^5.0.0",
80
+ "find-my-way": "^9.4.0"
50
81
  },
51
82
  "tsd": {
52
83
  "directory": "test/types"
53
84
  },
54
85
  "publishConfig": {
55
86
  "access": "public"
56
- },
57
- "tap": {
58
- "disable-coverage": true
59
87
  }
60
88
  }