@gasket/plugin-fastify 6.28.0 → 6.33.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/README.md +20 -0
- package/lib/index.js +22 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,6 +50,26 @@ module.exports = {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### middleware
|
|
54
|
+
|
|
55
|
+
You can configure which paths middleware will run on by adding the middleware configuration array to your local `gasket.config.js`. The array is made up of objects with the name of the middlware (Gasket plugin name) you want to configure and an array of path patterns representing the paths to match for this middleware. Pattern matching entries in the array can come in the form of path strings and/or regular expressions.
|
|
56
|
+
```js
|
|
57
|
+
middleware: [
|
|
58
|
+
{
|
|
59
|
+
plugin:'gasket-plugin-example', // Name of the Gasket plugin
|
|
60
|
+
paths: ['/api']
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
plugin:'@some/gasket-plugin-example',
|
|
64
|
+
paths: [/\/default/]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
plugin: '@another/gasket-plugin-example'
|
|
68
|
+
paths: ['/proxy', /\/home/]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
```
|
|
72
|
+
|
|
53
73
|
## Lifecycles
|
|
54
74
|
|
|
55
75
|
### middleware
|
package/lib/index.js
CHANGED
|
@@ -35,6 +35,7 @@ module.exports = {
|
|
|
35
35
|
const compression = require('compression');
|
|
36
36
|
|
|
37
37
|
const { logger, config } = gasket;
|
|
38
|
+
const { middleware: middlewareConfig } = config;
|
|
38
39
|
const excludedRoutesRegex = config.fastify && config.fastify.excludedRoutesRegex;
|
|
39
40
|
const app = fastify({ logger });
|
|
40
41
|
|
|
@@ -58,11 +59,30 @@ module.exports = {
|
|
|
58
59
|
app.use(compression());
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
const middlewares =
|
|
62
|
+
const middlewares = [];
|
|
63
|
+
await gasket.execApply('middleware', async (plugin, handler) => {
|
|
64
|
+
const middleware = handler(app);
|
|
65
|
+
if (middleware) {
|
|
66
|
+
if (middlewareConfig) {
|
|
67
|
+
const pluginName = plugin && plugin.name ? plugin.name : '';
|
|
68
|
+
const mwConfig = middlewareConfig.find(mw => mw.plugin === pluginName);
|
|
69
|
+
if (mwConfig) {
|
|
70
|
+
middleware.paths = mwConfig.paths;
|
|
71
|
+
if (excludedRoutesRegex) {
|
|
72
|
+
middleware.paths.push(excludedRoutesRegex);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
middlewares.push(middleware);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
62
79
|
|
|
63
80
|
debug('applied %s middleware layers to fastify', middlewares.length);
|
|
64
81
|
middlewares.forEach(layer => {
|
|
65
|
-
|
|
82
|
+
const { paths } = layer;
|
|
83
|
+
if (paths) {
|
|
84
|
+
app.use(paths, layer);
|
|
85
|
+
} else if (excludedRoutesRegex) {
|
|
66
86
|
app.use(excludedRoutesRegex, layer);
|
|
67
87
|
} else {
|
|
68
88
|
app.use(layer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.33.0",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"unicorn/filename-case": "error"
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "e19fab235461a16577f27ad30062b754233e05c9"
|
|
77
77
|
}
|