@gasket/plugin-fastify 7.0.0-next.56 → 7.0.0-next.58
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/lib/create-servers.js +8 -2
- package/lib/index.d.ts +14 -3
- package/lib/utils.js +25 -0
- package/package.json +6 -5
package/lib/create-servers.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="@gasket/plugin-https" />
|
|
2
2
|
/// <reference types="@gasket/plugin-logger" />
|
|
3
3
|
|
|
4
|
+
const { alignLogger } = require('./utils');
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Create the Fastify instance and setup the lifecycle hooks.
|
|
6
8
|
* Fastify is compatible with express middleware out of the box, so we can
|
|
@@ -10,7 +12,8 @@
|
|
|
10
12
|
// eslint-disable-next-line max-statements
|
|
11
13
|
module.exports = async function createServers(gasket, serverOpts) {
|
|
12
14
|
const fastify = require('fastify');
|
|
13
|
-
|
|
15
|
+
|
|
16
|
+
const { config } = gasket;
|
|
14
17
|
const {
|
|
15
18
|
fastify: {
|
|
16
19
|
routes,
|
|
@@ -19,8 +22,10 @@ module.exports = async function createServers(gasket, serverOpts) {
|
|
|
19
22
|
http2
|
|
20
23
|
} = config;
|
|
21
24
|
|
|
25
|
+
const fastifyLogger = alignLogger(gasket.logger);
|
|
26
|
+
|
|
22
27
|
// @ts-ignore
|
|
23
|
-
const app = fastify({ logger, trustProxy, http2 });
|
|
28
|
+
const app = fastify({ logger: fastifyLogger, trustProxy, http2 });
|
|
24
29
|
|
|
25
30
|
// allow consuming apps to directly append options to their server
|
|
26
31
|
await gasket.exec('fastify', app);
|
|
@@ -35,6 +40,7 @@ module.exports = async function createServers(gasket, serverOpts) {
|
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
43
|
+
// @ts-ignore
|
|
38
44
|
postRenderingStacks.forEach((stack) => app.use(stack));
|
|
39
45
|
|
|
40
46
|
return {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { MaybeAsync, MaybeMultiple, Plugin } from '@gasket/core';
|
|
2
|
+
import { Logger } from '@gasket/plugin-logger';
|
|
2
3
|
import type {
|
|
3
4
|
FastifyInstance,
|
|
4
5
|
FastifyRequest,
|
|
5
6
|
FastifyReply,
|
|
6
7
|
FastifyServerOptions
|
|
7
8
|
} from 'fastify';
|
|
9
|
+
import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2'
|
|
8
10
|
|
|
9
11
|
export type AppRoutes = Array<MaybeAsync<(app: FastifyInstance) => void>>;
|
|
10
12
|
|
|
@@ -20,7 +22,7 @@ declare module '@gasket/core' {
|
|
|
20
22
|
/** Trust proxy configuration */
|
|
21
23
|
trustProxy?: FastifyServerOptions['trustProxy'];
|
|
22
24
|
/** Glob pattern for source files setting up fastify routes */
|
|
23
|
-
routes?: Array<MaybeAsync<(app: FastifyInstance) => void>>;
|
|
25
|
+
routes?: Array<MaybeAsync<(app: FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse>) => void>>;
|
|
24
26
|
};
|
|
25
27
|
/** Middleware configuration */
|
|
26
28
|
middleware?: {
|
|
@@ -47,13 +49,22 @@ declare module '@gasket/core' {
|
|
|
47
49
|
|
|
48
50
|
export interface HookExecTypes {
|
|
49
51
|
middleware(
|
|
50
|
-
|
|
52
|
+
app: FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse>
|
|
51
53
|
): MaybeAsync<MaybeMultiple<Handler> & { paths?: (string | RegExp)[] }>;
|
|
52
|
-
fastify(
|
|
54
|
+
fastify(app: FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse>): MaybeAsync<void>;
|
|
53
55
|
errorMiddleware(): MaybeAsync<MaybeMultiple<ErrorHandler>>;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
type FastifyLogger = Logger & {
|
|
60
|
+
trace?: () => MaybeAsync<any>,
|
|
61
|
+
fatal?: () => MaybeAsync<any>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function alignLogger(
|
|
65
|
+
logger: Logger
|
|
66
|
+
): FastifyLogger
|
|
67
|
+
|
|
57
68
|
declare module 'create-gasket-app' {
|
|
58
69
|
export interface CreateContext {
|
|
59
70
|
/** Flag indicating if API app is enabled */
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const fallbackMap = {
|
|
3
|
+
fatal: 'error',
|
|
4
|
+
trace: 'debug'
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A helper function to ensure that all the required log levels
|
|
9
|
+
* for a Fastify server are present.
|
|
10
|
+
* @type {import('./index').alignLogger}
|
|
11
|
+
*/
|
|
12
|
+
function alignLogger(logger) {
|
|
13
|
+
const fastifyLogger = logger;
|
|
14
|
+
['fatal', 'trace'].map(level => {
|
|
15
|
+
if (!logger[level]) {
|
|
16
|
+
fastifyLogger[level] = logger[fallbackMap[level]];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return fastifyLogger;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
alignLogger
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-fastify",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.58",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,19 +39,20 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-fastify",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gasket/core": "7.0.0-next.
|
|
42
|
+
"@gasket/core": "7.0.0-next.58",
|
|
43
43
|
"cross-env": "^7.0.3",
|
|
44
44
|
"eslint": "^8.56.0",
|
|
45
45
|
"eslint-config-godaddy": "^7.1.1",
|
|
46
46
|
"eslint-plugin-jest": "^28.6.0",
|
|
47
47
|
"eslint-plugin-json": "^3.1.0",
|
|
48
48
|
"eslint-plugin-unicorn": "^55.0.0",
|
|
49
|
-
"fastify": "^
|
|
49
|
+
"fastify": "^4.28.1",
|
|
50
|
+
"http2": "^3.3.7",
|
|
50
51
|
"jest": "^29.7.0",
|
|
51
52
|
"typescript": "^5.4.5"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
|
-
"fastify": "^3
|
|
55
|
+
"fastify": "^3 || ^4"
|
|
55
56
|
},
|
|
56
57
|
"eslintConfig": {
|
|
57
58
|
"extends": [
|
|
@@ -70,5 +71,5 @@
|
|
|
70
71
|
"eslintIgnore": [
|
|
71
72
|
"generator"
|
|
72
73
|
],
|
|
73
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "800032d942a80eec38ae3cf80e738e73e411db7f"
|
|
74
75
|
}
|