@gasket/plugin-fastify 7.1.0 → 7.1.4
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 +13 -7
- package/generator/app/plugins/README.md +11 -0
- package/generator/app/plugins/routes-plugin.js +30 -0
- package/generator/app/plugins/routes-plugin.ts +29 -0
- package/generator/jest/test/index.test.js +1 -1
- package/generator/jest/test/index.test.ts +1 -1
- package/generator/mocha/test/index.test.js +1 -1
- package/generator/mocha/test/index.test.ts +1 -1
- package/lib/create-servers.js +10 -1
- package/lib/create.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/package.json +3 -3
- package/generator/app/routes/index.js +0 -28
- package/generator/app/routes/index.ts +0 -29
package/README.md
CHANGED
|
@@ -49,18 +49,24 @@ export default makeGasket({
|
|
|
49
49
|
});
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
### Route Definition
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Get the Fastify app instance.
|
|
54
|
+
Routes can be defined in a in-app plugin in the `plugins` directory. The plugin will hook the `fastify` lifecycle to add the routes to the fastify app.
|
|
57
55
|
|
|
58
56
|
```js
|
|
59
|
-
|
|
57
|
+
// plugins/routes-plugin.js
|
|
58
|
+
export default {
|
|
59
|
+
name: 'routes-plugin',
|
|
60
|
+
hooks: {
|
|
61
|
+
fastify: async function (gasket, app) {
|
|
62
|
+
app.get('/hello', (req, res) => {
|
|
63
|
+
res.send('Hello World!');
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
60
68
|
```
|
|
61
69
|
|
|
62
|
-
Each Gasket creates a single shared Fastify instance, ensuring consistent access to the same app instance wherever it's needed.
|
|
63
|
-
|
|
64
70
|
## Lifecycles
|
|
65
71
|
|
|
66
72
|
### fastify
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const defaultHandler = async (req, res) => {
|
|
2
|
+
if (res.statusCode === 200) {
|
|
3
|
+
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: 'routes-plugin',
|
|
9
|
+
hooks: {
|
|
10
|
+
fastify(gasket, app) {
|
|
11
|
+
{{#if useSwagger }}
|
|
12
|
+
/**
|
|
13
|
+
* @swagger
|
|
14
|
+
*
|
|
15
|
+
* /default:
|
|
16
|
+
* get:
|
|
17
|
+
* summary: "Get default route"
|
|
18
|
+
* produces:
|
|
19
|
+
* - "application/json"
|
|
20
|
+
* responses:
|
|
21
|
+
* "200":
|
|
22
|
+
* description: "Returns welcome message."
|
|
23
|
+
* content:
|
|
24
|
+
* application/json
|
|
25
|
+
*/
|
|
26
|
+
{{/if }}
|
|
27
|
+
app.get('/default', defaultHandler);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const defaultHandler = async (req, res) => {
|
|
2
|
+
if (res.statusCode === 200) {
|
|
3
|
+
res.send({ message: 'Welcome to your default route...' });
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
export default {
|
|
7
|
+
name: 'routes-plugin',
|
|
8
|
+
hooks: {
|
|
9
|
+
fastify(gasket, app) {
|
|
10
|
+
{{#if useSwagger }}
|
|
11
|
+
/**
|
|
12
|
+
* @swagger
|
|
13
|
+
*
|
|
14
|
+
* /default:
|
|
15
|
+
* get:
|
|
16
|
+
* summary: "Get default route"
|
|
17
|
+
* produces:
|
|
18
|
+
* - "application/json"
|
|
19
|
+
* responses:
|
|
20
|
+
* "200":
|
|
21
|
+
* description: "Returns welcome message."
|
|
22
|
+
* content:
|
|
23
|
+
* application/json
|
|
24
|
+
*/
|
|
25
|
+
{{/if }}
|
|
26
|
+
app.get('/default', defaultHandler);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
package/lib/create-servers.js
CHANGED
|
@@ -9,8 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
// eslint-disable-next-line max-statements
|
|
11
11
|
module.exports = async function createServers(gasket, serverOpts) {
|
|
12
|
-
const
|
|
12
|
+
const fastify = require('fastify');
|
|
13
|
+
const { alignLogger } = require('./utils');
|
|
14
|
+
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
15
|
+
const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
|
|
16
|
+
const fastifyLogger = alignLogger(gasket.logger);
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const app = fastify({ logger: fastifyLogger, trustProxy, https, http2, disableRequestLogging });
|
|
20
|
+
|
|
13
21
|
// allow consuming apps to directly append options to their server
|
|
22
|
+
// @ts-ignore
|
|
14
23
|
await gasket.exec('fastify', app);
|
|
15
24
|
|
|
16
25
|
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
package/lib/create.js
CHANGED
|
@@ -55,6 +55,7 @@ module.exports = async function create(gasket, context) {
|
|
|
55
55
|
if (apiApp && addApiRoutes) {
|
|
56
56
|
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
57
57
|
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
58
|
+
gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js');
|
|
58
59
|
|
|
59
60
|
createTestFiles({ files, generatorDir, testPlugins, globIgnore });
|
|
60
61
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type AppRoutes = Array<MaybeAsync<(app: FastifyInstance) => void>>;
|
|
|
15
15
|
|
|
16
16
|
declare module '@gasket/core' {
|
|
17
17
|
export interface GasketActions {
|
|
18
|
+
/** @deprecated */
|
|
18
19
|
getFastifyApp(): FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>;
|
|
19
20
|
}
|
|
20
21
|
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const plugin = {
|
|
|
19
19
|
version,
|
|
20
20
|
description,
|
|
21
21
|
actions: {
|
|
22
|
+
/** @deprecated */
|
|
22
23
|
getFastifyApp(gasket) {
|
|
23
24
|
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
24
25
|
const { trustProxy = false, disableRequestLogging = true } = fastifyConfig;
|
|
@@ -40,7 +41,8 @@ const plugin = {
|
|
|
40
41
|
{
|
|
41
42
|
name: 'getFastifyApp',
|
|
42
43
|
description: 'Get the Fastify app instance',
|
|
43
|
-
link: 'README.md#getFastifyApp'
|
|
44
|
+
link: 'README.md#getFastifyApp',
|
|
45
|
+
deprecated: true
|
|
44
46
|
}
|
|
45
47
|
],
|
|
46
48
|
lifecycles: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.4",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"fastify": "^4.28.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@gasket/core": "^7.1.
|
|
43
|
+
"@gasket/core": "^7.1.4",
|
|
44
44
|
"cross-env": "^7.0.3",
|
|
45
45
|
"eslint": "^8.56.0",
|
|
46
46
|
"eslint-config-godaddy": "^7.1.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"jest": {
|
|
75
75
|
"rootDir": "test"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "7d77c8fbff84ea9ae18b0f6b265f25bbbc25135e"
|
|
78
78
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import gasket from '../gasket.js';
|
|
2
|
-
|
|
3
|
-
const app = gasket.actions.getFastifyApp();
|
|
4
|
-
|
|
5
|
-
export const defaultHandler = async (req, res) => {
|
|
6
|
-
if (res.statusCode === 200) {
|
|
7
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
{{#if useSwagger}}
|
|
12
|
-
/**
|
|
13
|
-
* @swagger
|
|
14
|
-
*
|
|
15
|
-
* /default:
|
|
16
|
-
* get:
|
|
17
|
-
* summary: "Get default route"
|
|
18
|
-
* produces:
|
|
19
|
-
* - "application/json"
|
|
20
|
-
* responses:
|
|
21
|
-
* "200":
|
|
22
|
-
* description: "Returns welcome message."
|
|
23
|
-
* content:
|
|
24
|
-
* application/json
|
|
25
|
-
*/
|
|
26
|
-
{{/if}}
|
|
27
|
-
app.get('/default', defaultHandler);
|
|
28
|
-
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
-
import gasket from '../gasket.js';
|
|
3
|
-
|
|
4
|
-
const app = gasket.actions.getFastifyApp();
|
|
5
|
-
|
|
6
|
-
export const defaultHandler = async (req: FastifyRequest, res: FastifyReply) => {
|
|
7
|
-
if (res.statusCode === 200) {
|
|
8
|
-
res.send({ message: 'Welcome to your default route...' });
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
{{#if useSwagger}}
|
|
13
|
-
/**
|
|
14
|
-
* @swagger
|
|
15
|
-
*
|
|
16
|
-
* /default:
|
|
17
|
-
* get:
|
|
18
|
-
* summary: "Get default route"
|
|
19
|
-
* produces:
|
|
20
|
-
* - "application/json"
|
|
21
|
-
* responses:
|
|
22
|
-
* "200":
|
|
23
|
-
* description: "Returns welcome message."
|
|
24
|
-
* content:
|
|
25
|
-
* application/json
|
|
26
|
-
*/
|
|
27
|
-
{{/if}}
|
|
28
|
-
app.get('/default', defaultHandler);
|
|
29
|
-
|