@fastify/express 2.0.2 → 2.2.0

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.
@@ -14,4 +14,5 @@ jobs:
14
14
  test:
15
15
  uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
16
16
  with:
17
+ lint: true
17
18
  license-check: true
package/.taprc ADDED
@@ -0,0 +1 @@
1
+ --no-coverage
package/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const fp = require('fastify-plugin')
4
- const symbols = require('fastify/lib/symbols')
5
4
  const Express = require('express')
6
5
  const kMiddlewares = Symbol('fastify-express-middlewares')
7
6
 
8
- function expressPlugin (fastify, options, next) {
7
+ function fastifyExpress (fastify, options, next) {
9
8
  const {
10
9
  expressHook = 'onRequest'
11
10
  } = options
@@ -22,7 +21,7 @@ function expressPlugin (fastify, options, next) {
22
21
 
23
22
  function use (path, fn) {
24
23
  if (typeof path === 'string') {
25
- const prefix = this[symbols.kRoutePrefix]
24
+ const prefix = this.prefix
26
25
  path = prefix + (path === '/' && prefix.length > 0 ? '' : path)
27
26
  }
28
27
  this[kMiddlewares].push([path, fn])
@@ -52,12 +51,10 @@ function expressPlugin (fastify, options, next) {
52
51
  req.raw.cookies = req.cookies
53
52
  }
54
53
 
55
- const originalProtocol = req.raw.protocol
56
54
  // Make it lazy as it does a bit of work
57
55
  Object.defineProperty(req.raw, 'protocol', {
58
56
  get () {
59
- // added in Fastify@3.5, so handle it missing
60
- return req.protocol || originalProtocol
57
+ return req.protocol
61
58
  }
62
59
  })
63
60
 
@@ -90,7 +87,9 @@ function expressPlugin (fastify, options, next) {
90
87
  next()
91
88
  }
92
89
 
93
- module.exports = fp(expressPlugin, {
90
+ module.exports = fp(fastifyExpress, {
94
91
  fastify: '4.x',
95
92
  name: '@fastify/express'
96
93
  })
94
+ module.exports.default = fastifyExpress
95
+ module.exports.fastifyExpress = fastifyExpress
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@fastify/express",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "description": "Express compatibility layer for Fastify",
5
5
  "main": "index.js",
6
- "types": "index.d.ts",
6
+ "types": "types/index.d.ts",
7
7
  "scripts": {
8
- "test": "standard && tap --no-coverage test/*.test.js && tsd"
8
+ "lint": "standard",
9
+ "test": "npm run test:unit && npm run test:typescript",
10
+ "test:unit": "tap",
11
+ "test:typescript": "tsd"
9
12
  },
10
13
  "repository": {
11
14
  "type": "git",
@@ -25,20 +28,20 @@
25
28
  },
26
29
  "homepage": "https://github.com/fastify/fastify-express#readme",
27
30
  "devDependencies": {
31
+ "@fastify/formbody": "^7.0.1",
28
32
  "@types/express": "^4.17.1",
29
33
  "@types/node": "*",
30
34
  "body-parser": "^1.20.0",
31
35
  "cors": "^2.8.5",
32
36
  "fastify": "^4.0.0-rc.3",
33
- "@fastify/formbody": "^7.0.1",
34
- "helmet": "^5.0.0",
37
+ "helmet": "^6.0.0",
35
38
  "passport": "^0.6.0",
36
39
  "passport-http-bearer": "^1.0.1",
37
40
  "serve-static": "^1.14.1",
38
41
  "simple-get": "^4.0.0",
39
42
  "standard": "^17.0.0",
40
43
  "tap": "^16.0.0",
41
- "tsd": "^0.22.0"
44
+ "tsd": "^0.24.1"
42
45
  },
43
46
  "dependencies": {
44
47
  "express": "^4.17.1",
@@ -0,0 +1,31 @@
1
+ import { Application } from 'express'
2
+ import { FastifyPluginCallback } from 'fastify'
3
+
4
+ declare module 'fastify' {
5
+ interface FastifyInstance {
6
+ /**
7
+ * Express middleware function
8
+ */
9
+ use: Application['use']
10
+
11
+ /**
12
+ * Express application instance
13
+ */
14
+ express: Application
15
+ }
16
+ }
17
+
18
+ type FastifyExpress = FastifyPluginCallback<fastifyExpress.FastifyExpressOptions>
19
+
20
+ declare namespace fastifyExpress {
21
+
22
+ export interface FastifyExpressOptions {
23
+ expressHook?: string;
24
+ }
25
+
26
+ export const fastifyExpress: FastifyExpress
27
+ export { fastifyExpress as default }
28
+ }
29
+
30
+ declare function fastifyExpress(...params: Parameters<FastifyExpress>): ReturnType<FastifyExpress>
31
+ export = fastifyExpress
@@ -0,0 +1,19 @@
1
+ import Fastify from 'fastify'
2
+ import fastifyExpress from '..'
3
+ import { expectType } from "tsd"
4
+ import { Application } from 'express'
5
+
6
+ const app = Fastify()
7
+
8
+ app.register(fastifyExpress)
9
+ app.register(fastifyExpress, {
10
+ expressHook: 'onRequest'
11
+ })
12
+
13
+ expectType<Application>(app.express)
14
+
15
+ app.express.disable('x-powered-by')
16
+
17
+ app.use('/world', (_req, res) => {
18
+ res.sendStatus(200)
19
+ })
package/index.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import { Application } from 'express'
2
- import { FastifyPluginCallback } from 'fastify'
3
-
4
- declare module 'fastify' {
5
- interface FastifyInstance {
6
- /**
7
- * Express middleware function
8
- */
9
- use: Application['use']
10
-
11
- /**
12
- * Express application instance
13
- */
14
- express: Application
15
- }
16
- }
17
-
18
- declare const fastifyExpress: FastifyPluginCallback
19
-
20
- export default fastifyExpress
@@ -1,12 +0,0 @@
1
- import Fastify from 'fastify'
2
- import fastifyExpress from '../..'
3
-
4
- const app = Fastify()
5
-
6
- app.register(fastifyExpress)
7
-
8
- app.express.disable('x-powered-by')
9
-
10
- app.use('/world', (_req, res) => {
11
- res.sendStatus(200)
12
- })