@gasket/plugin-fastify 6.0.0 → 6.10.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/CHANGELOG.md +20 -1
- package/index.d.ts +28 -0
- package/index.js +8 -2
- package/package.json +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# `@gasket/plugin-fastify`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### 6.10.0
|
|
4
|
+
|
|
5
|
+
- TypeScript definitions for config & lifecycles ([#311])
|
|
6
|
+
|
|
7
|
+
### 6.0.5
|
|
8
|
+
|
|
9
|
+
- Filter falsy middleware ([#255])
|
|
10
|
+
|
|
11
|
+
### 6.0.1
|
|
12
|
+
|
|
13
|
+
- Fix to add `res.locals` for attaching data ([#250])
|
|
14
|
+
|
|
15
|
+
### 6.0.0
|
|
16
|
+
|
|
17
|
+
Enable middleware support ([#172])
|
|
4
18
|
- Add `middie@5` as dependency
|
|
5
19
|
- Register `middie` to enable Fastify middleware
|
|
6
20
|
|
|
@@ -12,4 +26,9 @@ Enable middleware support
|
|
|
12
26
|
|
|
13
27
|
- [#88] Initial release.
|
|
14
28
|
|
|
29
|
+
|
|
15
30
|
[#88]: https://github.com/godaddy/gasket/pull/88
|
|
31
|
+
[#172]: https://github.com/godaddy/gasket/pull/172
|
|
32
|
+
[#250]: https://github.com/godaddy/gasket/pull/250
|
|
33
|
+
[#255]: https://github.com/godaddy/gasket/pull/255
|
|
34
|
+
[#311]: https://github.com/godaddy/gasket/pull/311
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { GasketConfig, HookExecTypes, MaybeAsync, MaybeMultiple } from '@gasket/engine';
|
|
2
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
|
3
|
+
|
|
4
|
+
declare module '@gasket/engine' {
|
|
5
|
+
export interface GasketConfig {
|
|
6
|
+
compression?: boolean,
|
|
7
|
+
excludedRoutesRegex?: RegExp
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// The middie middleware is added for express compatibility
|
|
11
|
+
type Handler = (
|
|
12
|
+
req: FastifyRequest,
|
|
13
|
+
res: FastifyReply,
|
|
14
|
+
next: (error?: Error) => void
|
|
15
|
+
) => void;
|
|
16
|
+
type ErrorHandler = (
|
|
17
|
+
error: Error,
|
|
18
|
+
req: FastifyRequest,
|
|
19
|
+
res: FastifyReply,
|
|
20
|
+
next: (error?: Error) => void
|
|
21
|
+
) => void;
|
|
22
|
+
|
|
23
|
+
export interface HookExecTypes {
|
|
24
|
+
middleware(fastify: FastifyInstance): MaybeAsync<MaybeMultiple<Handler>>,
|
|
25
|
+
fastify(fastify: FastifyInstance): MaybeAsync<void>,
|
|
26
|
+
errorMiddleware(fastify: FastifyInstance): MaybeAsync<MaybeMultiple<ErrorHandler>>
|
|
27
|
+
}
|
|
28
|
+
}
|
package/index.js
CHANGED
|
@@ -41,6 +41,12 @@ module.exports = {
|
|
|
41
41
|
// Enable middleware for fastify@3
|
|
42
42
|
await app.register(middie);
|
|
43
43
|
|
|
44
|
+
// Add express-like `res.locals` object attaching data
|
|
45
|
+
app.use(function attachLocals(req, res, next) {
|
|
46
|
+
res.locals = {};
|
|
47
|
+
next();
|
|
48
|
+
});
|
|
49
|
+
|
|
44
50
|
if (excludedRoutesRegex) {
|
|
45
51
|
app.use(excludedRoutesRegex, cookieParser());
|
|
46
52
|
} else {
|
|
@@ -52,7 +58,7 @@ module.exports = {
|
|
|
52
58
|
app.use(compression());
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
const middlewares = await gasket.exec('middleware', app);
|
|
61
|
+
const middlewares = (await gasket.exec('middleware', app)).filter(Boolean);
|
|
56
62
|
|
|
57
63
|
debug('applied %s middleware layers to fastify', middlewares.length);
|
|
58
64
|
middlewares.forEach(layer => {
|
|
@@ -66,7 +72,7 @@ module.exports = {
|
|
|
66
72
|
// allow consuming apps to directly append options to their server
|
|
67
73
|
await gasket.exec('fastify', app);
|
|
68
74
|
|
|
69
|
-
const postRenderingStacks = await gasket.exec('errorMiddleware');
|
|
75
|
+
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
70
76
|
postRenderingStacks.forEach(stack => app.use(stack));
|
|
71
77
|
|
|
72
78
|
return {
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.10.0",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"lint": "eslint index.js test",
|
|
8
9
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -41,12 +42,14 @@
|
|
|
41
42
|
"middie": "5.1.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
45
|
+
"@gasket/engine": "^6.10.0",
|
|
44
46
|
"assume": "^2.3.0",
|
|
45
47
|
"assume-sinon": "^1.1.0",
|
|
46
48
|
"eslint": "^7.17.0",
|
|
47
49
|
"eslint-config-godaddy": "^4.0.1",
|
|
48
50
|
"eslint-plugin-json": "^2.1.2",
|
|
49
51
|
"eslint-plugin-mocha": "^8.0.0",
|
|
52
|
+
"eslint-plugin-unicorn": "^39.0.0",
|
|
50
53
|
"fastify": "^3.3.0",
|
|
51
54
|
"mocha": "^8.2.1",
|
|
52
55
|
"nyc": "^15.1.0",
|
|
@@ -56,5 +59,16 @@
|
|
|
56
59
|
"peerDependencies": {
|
|
57
60
|
"fastify": "^3.0.0"
|
|
58
61
|
},
|
|
59
|
-
"
|
|
62
|
+
"eslintConfig": {
|
|
63
|
+
"extends": [
|
|
64
|
+
"godaddy"
|
|
65
|
+
],
|
|
66
|
+
"plugins": [
|
|
67
|
+
"unicorn"
|
|
68
|
+
],
|
|
69
|
+
"rules": {
|
|
70
|
+
"unicorn/filename-case": "error"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "eca8f68eb2389d28f47f2fcf0b06b2b7f9575177"
|
|
60
74
|
}
|