@gasket/plugin-fastify 7.0.0-next.64 → 7.0.0-next.66
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 +1 -27
- package/lib/create.js +1 -1
- package/lib/index.d.ts +13 -12
- package/lib/index.js +16 -0
- package/lib/utils.js +1 -0
- package/package.json +3 -3
package/lib/create-servers.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/// <reference types="@gasket/plugin-https" />
|
|
2
2
|
/// <reference types="@gasket/plugin-logger" />
|
|
3
3
|
|
|
4
|
-
const { alignLogger } = require('./utils');
|
|
5
|
-
|
|
6
4
|
/**
|
|
7
5
|
* Create the Fastify instance and setup the lifecycle hooks.
|
|
8
6
|
* Fastify is compatible with express middleware out of the box, so we can
|
|
@@ -11,34 +9,10 @@ const { alignLogger } = require('./utils');
|
|
|
11
9
|
*/
|
|
12
10
|
// eslint-disable-next-line max-statements
|
|
13
11
|
module.exports = async function createServers(gasket, serverOpts) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const { config } = gasket;
|
|
17
|
-
const {
|
|
18
|
-
fastify: {
|
|
19
|
-
routes,
|
|
20
|
-
trustProxy = false
|
|
21
|
-
} = {},
|
|
22
|
-
http2
|
|
23
|
-
} = config;
|
|
24
|
-
|
|
25
|
-
const fastifyLogger = alignLogger(gasket.logger);
|
|
26
|
-
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
const app = fastify({ logger: fastifyLogger, trustProxy, http2 });
|
|
29
|
-
|
|
12
|
+
const app = gasket.actions.getFastifyApp();
|
|
30
13
|
// allow consuming apps to directly append options to their server
|
|
31
14
|
await gasket.exec('fastify', app);
|
|
32
15
|
|
|
33
|
-
if (routes) {
|
|
34
|
-
for (const route of routes) {
|
|
35
|
-
if (typeof route !== 'function') {
|
|
36
|
-
throw new Error('Route must be a function');
|
|
37
|
-
}
|
|
38
|
-
await route(app);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
16
|
const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean);
|
|
43
17
|
// @ts-ignore
|
|
44
18
|
postRenderingStacks.forEach((stack) => app.use(stack));
|
package/lib/create.js
CHANGED
|
@@ -52,7 +52,7 @@ module.exports = async function create(gasket, context) {
|
|
|
52
52
|
|
|
53
53
|
if ('apiApp' in context && context.apiApp) {
|
|
54
54
|
const globIgnore = typescript ? '!(*.js)' : '!(*.ts)';
|
|
55
|
-
files.add(`${generatorDir}/app/**/${globIgnore}`)
|
|
55
|
+
files.add(`${generatorDir}/app/**/${globIgnore}`);
|
|
56
56
|
|
|
57
57
|
createTestFiles({ files, generatorDir, testPlugins, globIgnore });
|
|
58
58
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,13 +4,21 @@ import type {
|
|
|
4
4
|
FastifyInstance,
|
|
5
5
|
FastifyRequest,
|
|
6
6
|
FastifyReply,
|
|
7
|
-
FastifyServerOptions
|
|
7
|
+
FastifyServerOptions,
|
|
8
|
+
FastifyBaseLogger,
|
|
9
|
+
FastifyTypeProviderDefault,
|
|
10
|
+
RawServerDefault
|
|
8
11
|
} from 'fastify';
|
|
9
|
-
import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2'
|
|
12
|
+
import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2';
|
|
13
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
10
14
|
|
|
11
15
|
export type AppRoutes = Array<MaybeAsync<(app: FastifyInstance) => void>>;
|
|
12
16
|
|
|
13
17
|
declare module '@gasket/core' {
|
|
18
|
+
export interface GasketActions {
|
|
19
|
+
getFastifyApp(): FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export interface GasketConfig {
|
|
15
23
|
fastify?: {
|
|
16
24
|
/** Enable compression */
|
|
@@ -21,8 +29,6 @@ declare module '@gasket/core' {
|
|
|
21
29
|
excludedRoutesRegex?: RegExp;
|
|
22
30
|
/** Trust proxy configuration */
|
|
23
31
|
trustProxy?: FastifyServerOptions['trustProxy'];
|
|
24
|
-
/** Glob pattern for source files setting up fastify routes */
|
|
25
|
-
routes?: Array<MaybeAsync<(app: FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse>) => void>>;
|
|
26
32
|
};
|
|
27
33
|
/** Middleware configuration */
|
|
28
34
|
middleware?: {
|
|
@@ -49,21 +55,16 @@ declare module '@gasket/core' {
|
|
|
49
55
|
|
|
50
56
|
export interface HookExecTypes {
|
|
51
57
|
middleware(
|
|
52
|
-
app: FastifyInstance<
|
|
58
|
+
app: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>
|
|
53
59
|
): MaybeAsync<MaybeMultiple<Handler> & { paths?: (string | RegExp)[] }>;
|
|
54
|
-
fastify(app: FastifyInstance<
|
|
60
|
+
fastify(app: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>): MaybeAsync<void>;
|
|
55
61
|
errorMiddleware(): MaybeAsync<MaybeMultiple<ErrorHandler>>;
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
type FastifyLogger = Logger & {
|
|
60
|
-
trace?: () => MaybeAsync<any>,
|
|
61
|
-
fatal?: () => MaybeAsync<any>
|
|
62
|
-
}
|
|
63
|
-
|
|
64
65
|
export function alignLogger(
|
|
65
66
|
logger: Logger
|
|
66
|
-
):
|
|
67
|
+
): FastifyBaseLogger
|
|
67
68
|
|
|
68
69
|
declare module 'create-gasket-app' {
|
|
69
70
|
export interface CreateContext {
|
package/lib/index.js
CHANGED
|
@@ -8,12 +8,28 @@ const {
|
|
|
8
8
|
} = require('../package.json');
|
|
9
9
|
const create = require('./create');
|
|
10
10
|
const createServers = require('./create-servers');
|
|
11
|
+
const fastify = require('fastify');
|
|
12
|
+
const { alignLogger } = require('./utils');
|
|
13
|
+
|
|
14
|
+
let app;
|
|
11
15
|
|
|
12
16
|
/** @type {import('@gasket/core').Plugin} */
|
|
13
17
|
const plugin = {
|
|
14
18
|
name,
|
|
15
19
|
version,
|
|
16
20
|
description,
|
|
21
|
+
actions: {
|
|
22
|
+
getFastifyApp(gasket) {
|
|
23
|
+
const { fastify: fastifyConfig = {}, http2, https } = gasket.config;
|
|
24
|
+
const { trustProxy = false } = fastifyConfig;
|
|
25
|
+
const fastifyLogger = alignLogger(gasket.logger);
|
|
26
|
+
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
app ??= fastify({ logger: fastifyLogger, trustProxy, https, http2 });
|
|
29
|
+
|
|
30
|
+
return app;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
17
33
|
hooks: {
|
|
18
34
|
create,
|
|
19
35
|
createServers,
|
package/lib/utils.js
CHANGED
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.66",
|
|
4
4
|
"description": "Adds fastify support to your application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
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.66",
|
|
43
43
|
"cross-env": "^7.0.3",
|
|
44
44
|
"eslint": "^8.56.0",
|
|
45
45
|
"eslint-config-godaddy": "^7.1.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"jest": {
|
|
75
75
|
"rootDir": "test"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "73d57d790d06eaf7d75c74bd89a9505f49be73ea"
|
|
78
78
|
}
|