@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.
- package/.github/workflows/{nodejs.yml → ci.yml} +1 -0
- package/.taprc +1 -0
- package/index.js +6 -7
- package/package.json +9 -6
- package/types/index.d.ts +31 -0
- package/types/index.test-d.ts +19 -0
- package/index.d.ts +0 -20
- package/test/types/index.ts +0 -12
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
|
|
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
|
|
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
|
-
|
|
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(
|
|
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
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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.
|
|
44
|
+
"tsd": "^0.24.1"
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
44
47
|
"express": "^4.17.1",
|
package/types/index.d.ts
ADDED
|
@@ -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
|
package/test/types/index.ts
DELETED