From 2317e8928071533aa277e9ec5fa6e5d1132dc76a Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Wed, 15 Jan 2025 13:51:55 -0800 Subject: [PATCH 1/4] @gasket/plugin-express: deprecate action, tune up create-servers and re-apply old pattern, update generated files to create app-level routes plugin --- packages/gasket-plugin-express/README.md | 21 ++++++++----- .../generator/app/plugins/README.md | 11 +++++++ .../generator/app/plugins/routes-plugin.js | 30 +++++++++++++++++++ .../generator/app/plugins/routes-plugin.ts | 30 +++++++++++++++++++ .../generator/app/routes/index.js | 27 ----------------- .../generator/app/routes/index.ts | 28 ----------------- .../generator/jest/test/index.test.js | 2 +- .../generator/jest/test/index.test.ts | 2 +- .../generator/mocha/test/index.test.js | 2 +- .../generator/mocha/test/index.test.ts | 2 +- .../lib/create-servers.js | 6 +++- packages/gasket-plugin-express/lib/create.js | 1 + packages/gasket-plugin-express/lib/index.d.ts | 1 + packages/gasket-plugin-express/lib/index.js | 4 ++- .../gasket-plugin-express/test/plugin.test.js | 9 ++++-- 15 files changed, 105 insertions(+), 71 deletions(-) create mode 100644 packages/gasket-plugin-express/generator/app/plugins/README.md create mode 100644 packages/gasket-plugin-express/generator/app/plugins/routes-plugin.js create mode 100644 packages/gasket-plugin-express/generator/app/plugins/routes-plugin.ts delete mode 100644 packages/gasket-plugin-express/generator/app/routes/index.js delete mode 100644 packages/gasket-plugin-express/generator/app/routes/index.ts diff --git a/packages/gasket-plugin-express/README.md b/packages/gasket-plugin-express/README.md index d35520076..dbdbeba98 100644 --- a/packages/gasket-plugin-express/README.md +++ b/packages/gasket-plugin-express/README.md @@ -51,19 +51,24 @@ export default makeGasket({ } }); ``` +### Route Definition -## Actions - -### getExpressApp - -Get the Express app instance. +Routes can be defined in a in-app plugin in the `plugins` directory. The plugin will hook the `express` lifecycle to add the routes to the express app. ```js -const app = actions.gasket.getExpressApp(); +// plugins/routes-plugin.js +export default { + name: 'routes-plugin', + hooks: { + express: async function (gasket, app) { + app.get('/hello', (req, res) => { + res.send('Hello World!'); + }); + } + } +}; ``` -Each Gasket creates a single shared Express instance, ensuring consistent access to the same app instance wherever it's needed. - ## Lifecycles ### express diff --git a/packages/gasket-plugin-express/generator/app/plugins/README.md b/packages/gasket-plugin-express/generator/app/plugins/README.md new file mode 100644 index 000000000..560b9fab1 --- /dev/null +++ b/packages/gasket-plugin-express/generator/app/plugins/README.md @@ -0,0 +1,11 @@ +# Local Plugins + +### Routes plugin + +A local plugin is used to define Express routes. The plugin hooks the `express` lifecycle and mutates the Express app. + +The following routes are available: + +```javascript +GET /default +``` diff --git a/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.js b/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.js new file mode 100644 index 000000000..77d1b08d8 --- /dev/null +++ b/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.js @@ -0,0 +1,30 @@ +export const defaultHandler = async (req, res) => { + res.status(200).json({ + message: 'Welcome to your default route...' + }); +}; + +export default { + name: 'routes-plugin', + hooks: { + express(gasket, app) { + {{#if useSwagger }} + /** + * @swagger + * + * /default: + * get: + * summary: "Get default route" + * produces: + * - "application/json" + * responses: + * "200": + * description: "Returns welcome message." + * content: + * application/json + */ + {{/if }} + app.get('/default', defaultHandler); + } + } +} diff --git a/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.ts b/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.ts new file mode 100644 index 000000000..77d1b08d8 --- /dev/null +++ b/packages/gasket-plugin-express/generator/app/plugins/routes-plugin.ts @@ -0,0 +1,30 @@ +export const defaultHandler = async (req, res) => { + res.status(200).json({ + message: 'Welcome to your default route...' + }); +}; + +export default { + name: 'routes-plugin', + hooks: { + express(gasket, app) { + {{#if useSwagger }} + /** + * @swagger + * + * /default: + * get: + * summary: "Get default route" + * produces: + * - "application/json" + * responses: + * "200": + * description: "Returns welcome message." + * content: + * application/json + */ + {{/if }} + app.get('/default', defaultHandler); + } + } +} diff --git a/packages/gasket-plugin-express/generator/app/routes/index.js b/packages/gasket-plugin-express/generator/app/routes/index.js deleted file mode 100644 index 0a1499485..000000000 --- a/packages/gasket-plugin-express/generator/app/routes/index.js +++ /dev/null @@ -1,27 +0,0 @@ -import gasket from '../gasket.js'; - -const app = gasket.actions.getExpressApp(); - -export const defaultHandler = async (req, res) => { - res.status(200).json({ - message: 'Welcome to your default route...' - }); -}; - -{{#if useSwagger}} -/** -* @swagger -* -* /default: -* get: -* summary: "Get default route" -* produces: -* - "application/json" -* responses: -* "200": -* description: "Returns welcome message." -* content: -* application/json -*/ -{{/if}} -app.get('/default', defaultHandler); diff --git a/packages/gasket-plugin-express/generator/app/routes/index.ts b/packages/gasket-plugin-express/generator/app/routes/index.ts deleted file mode 100644 index 8e7c7ca95..000000000 --- a/packages/gasket-plugin-express/generator/app/routes/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { Request, Response } from 'express'; -import gasket from '../gasket.js'; - -const app = gasket.actions.getExpressApp(); - -export const defaultHandler = async (req: Request, res: Response) => { - res.status(200).json({ - message: 'Welcome to your default route...' - }); -} - -{{#if useSwagger}} -/** -* @swagger -* -* /default: -* get: -* summary: "Get default route" -* produces: -* - "application/json" -* responses: -* "200": -* description: "Returns welcome message." -* content: -* application/json -*/ -{{/if}} -app.get('/default', defaultHandler); diff --git a/packages/gasket-plugin-express/generator/jest/test/index.test.js b/packages/gasket-plugin-express/generator/jest/test/index.test.js index 78faeae72..a85a28c39 100644 --- a/packages/gasket-plugin-express/generator/jest/test/index.test.js +++ b/packages/gasket-plugin-express/generator/jest/test/index.test.js @@ -1,4 +1,4 @@ -import { defaultHandler } from '../routes'; +import { defaultHandler } from '../plugins/routes-plugin.js'; import { jest, expect, beforeEach } from '@jest/globals'; describe('Routes', () => { diff --git a/packages/gasket-plugin-express/generator/jest/test/index.test.ts b/packages/gasket-plugin-express/generator/jest/test/index.test.ts index 84335f4f0..b9d4907a7 100644 --- a/packages/gasket-plugin-express/generator/jest/test/index.test.ts +++ b/packages/gasket-plugin-express/generator/jest/test/index.test.ts @@ -1,5 +1,5 @@ import { jest, describe, beforeEach, it, expect } from '@jest/globals'; -import { defaultHandler } from '../routes'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse; diff --git a/packages/gasket-plugin-express/generator/mocha/test/index.test.js b/packages/gasket-plugin-express/generator/mocha/test/index.test.js index bc46e27db..8f1b2fafc 100644 --- a/packages/gasket-plugin-express/generator/mocha/test/index.test.js +++ b/packages/gasket-plugin-express/generator/mocha/test/index.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import sinon from 'sinon'; -import { defaultHandler } from '../routes/index.js'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse, jsonSpy; diff --git a/packages/gasket-plugin-express/generator/mocha/test/index.test.ts b/packages/gasket-plugin-express/generator/mocha/test/index.test.ts index bc46e27db..8f1b2fafc 100644 --- a/packages/gasket-plugin-express/generator/mocha/test/index.test.ts +++ b/packages/gasket-plugin-express/generator/mocha/test/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import sinon from 'sinon'; -import { defaultHandler } from '../routes/index.js'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse, jsonSpy; diff --git a/packages/gasket-plugin-express/lib/create-servers.js b/packages/gasket-plugin-express/lib/create-servers.js index 1288c283e..a4a0a9bb7 100644 --- a/packages/gasket-plugin-express/lib/create-servers.js +++ b/packages/gasket-plugin-express/lib/create-servers.js @@ -7,7 +7,11 @@ * @type {import('@gasket/core').HookHandler<'createServers'>} */ module.exports = async function createServers(gasket, serverOpts) { - const app = gasket.actions.getExpressApp(); + const express = require('express'); + const { http2 } = gasket.config; + const app = http2 ? require('http2-express')(express) : express(); + + app.use(require('cookie-parser')()); await gasket.exec('express', app); diff --git a/packages/gasket-plugin-express/lib/create.js b/packages/gasket-plugin-express/lib/create.js index 2647eb9f0..df46ecfd9 100644 --- a/packages/gasket-plugin-express/lib/create.js +++ b/packages/gasket-plugin-express/lib/create.js @@ -55,6 +55,7 @@ module.exports = async function create(gasket, context) { if (apiApp && addApiRoutes) { const globIgnore = typescript ? '!(*.js)' : '!(*.ts)'; files.add(`${generatorDir}/app/**/${globIgnore}`); + gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js'); createTestFiles({ files, generatorDir, testPlugins, globIgnore }); } diff --git a/packages/gasket-plugin-express/lib/index.d.ts b/packages/gasket-plugin-express/lib/index.d.ts index 993ebc0cd..3a36530fd 100644 --- a/packages/gasket-plugin-express/lib/index.d.ts +++ b/packages/gasket-plugin-express/lib/index.d.ts @@ -4,6 +4,7 @@ import type { Application, ErrorRequestHandler, Handler } from 'express'; declare module '@gasket/core' { export interface GasketActions { + /** @deprecated */ getExpressApp(): Application; } export interface GasketConfig { diff --git a/packages/gasket-plugin-express/lib/index.js b/packages/gasket-plugin-express/lib/index.js index b14b98b19..e33ab9797 100644 --- a/packages/gasket-plugin-express/lib/index.js +++ b/packages/gasket-plugin-express/lib/index.js @@ -14,6 +14,7 @@ const plugin = { version, description, actions: { + /** @deprecated */ getExpressApp(gasket) { const express = require('express'); const { http2 } = gasket.config; @@ -41,7 +42,8 @@ const plugin = { { name: 'getExpressApp', description: 'Get the Express app instance', - link: 'README.md#getExpressApp' + link: 'README.md#getExpressApp', + deprecated: true } ], guides: [ diff --git a/packages/gasket-plugin-express/test/plugin.test.js b/packages/gasket-plugin-express/test/plugin.test.js index 5169ab832..1f0ac5e9a 100644 --- a/packages/gasket-plugin-express/test/plugin.test.js +++ b/packages/gasket-plugin-express/test/plugin.test.js @@ -79,14 +79,19 @@ describe('createServers', () => { expect(result).toEqual({ handler: app }); }); - it('returns the handler as http2 bridge app', async function () { + it('attaches cookie parser middleware', async function () { + await plugin.hooks.createServers(gasket, {}); + expect(app.use).toHaveBeenCalledWith(cookieParserMiddleware); + }); + + it('action: returns the handler as http2 bridge app(deprecated)', async function () { gasket.actions.getExpressApp.mockReturnValueOnce(bridgedApp); gasket.config.http2 = 8080; const result = await plugin.hooks.createServers(gasket); expect(result).toEqual({ handler: bridgedApp }); }); - it('attaches cookie parser middleware', async function () { + it('action: attaches cookie parser middleware(deprecated)', async function () { plugin.actions.getExpressApp(gasket); expect(app.use).toHaveBeenCalledWith(cookieParserMiddleware); }); From 148266a3a91a1002a06c1581002f886636b7298b Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Wed, 15 Jan 2025 13:52:38 -0800 Subject: [PATCH 2/4] @gasket/plugin-fastify: deprecate action, tune up create-servers and re-apply old pattern, update generated files to create app-level routes plugin --- packages/gasket-plugin-fastify/README.md | 20 ++++++++----- .../generator/app/plugins/README.md | 11 +++++++ .../generator/app/plugins/routes-plugin.js | 30 +++++++++++++++++++ .../generator/app/plugins/routes-plugin.ts | 29 ++++++++++++++++++ .../generator/app/routes/index.js | 28 ----------------- .../generator/app/routes/index.ts | 29 ------------------ .../generator/jest/test/index.test.js | 2 +- .../generator/jest/test/index.test.ts | 2 +- .../generator/mocha/test/index.test.js | 2 +- .../generator/mocha/test/index.test.ts | 2 +- .../lib/create-servers.js | 11 ++++++- packages/gasket-plugin-fastify/lib/create.js | 1 + packages/gasket-plugin-fastify/lib/index.d.ts | 1 + packages/gasket-plugin-fastify/lib/index.js | 4 ++- .../gasket-plugin-fastify/test/plugin.test.js | 5 +--- 15 files changed, 103 insertions(+), 74 deletions(-) create mode 100644 packages/gasket-plugin-fastify/generator/app/plugins/README.md create mode 100644 packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.js create mode 100644 packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.ts delete mode 100644 packages/gasket-plugin-fastify/generator/app/routes/index.js delete mode 100644 packages/gasket-plugin-fastify/generator/app/routes/index.ts diff --git a/packages/gasket-plugin-fastify/README.md b/packages/gasket-plugin-fastify/README.md index cb2e375fb..a39c47515 100644 --- a/packages/gasket-plugin-fastify/README.md +++ b/packages/gasket-plugin-fastify/README.md @@ -49,18 +49,24 @@ export default makeGasket({ }); ``` -## Actions +### Route Definition -### getFastifyApp - -Get the Fastify app instance. +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. ```js -const app = actions.gasket.getFastifyApp(); +// plugins/routes-plugin.js +export default { + name: 'routes-plugin', + hooks: { + fastify: async function (gasket, app) { + app.get('/hello', (req, res) => { + res.send('Hello World!'); + }); + } + } +}; ``` -Each Gasket creates a single shared Fastify instance, ensuring consistent access to the same app instance wherever it's needed. - ## Lifecycles ### fastify diff --git a/packages/gasket-plugin-fastify/generator/app/plugins/README.md b/packages/gasket-plugin-fastify/generator/app/plugins/README.md new file mode 100644 index 000000000..94bd7df8d --- /dev/null +++ b/packages/gasket-plugin-fastify/generator/app/plugins/README.md @@ -0,0 +1,11 @@ +# Local Plugins + +### Routes plugin + +A local plugin is used to define Fastify routes. The plugin hooks the `fastify` lifecycle and mutates the Fastify app. + +The following routes are available: + +```javascript +GET /default +``` diff --git a/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.js b/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.js new file mode 100644 index 000000000..83410cfd3 --- /dev/null +++ b/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.js @@ -0,0 +1,30 @@ +export const defaultHandler = async (req, res) => { + if (res.statusCode === 200) { + res.send({ message: 'Welcome to your default route...' }); + } +}; + +export default { + name: 'routes-plugin', + hooks: { + fastify(gasket, app) { + {{#if useSwagger }} + /** + * @swagger + * + * /default: + * get: + * summary: "Get default route" + * produces: + * - "application/json" + * responses: + * "200": + * description: "Returns welcome message." + * content: + * application/json + */ + {{/if }} + app.get('/default', defaultHandler); + } + } +} diff --git a/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.ts b/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.ts new file mode 100644 index 000000000..06ceef0ed --- /dev/null +++ b/packages/gasket-plugin-fastify/generator/app/plugins/routes-plugin.ts @@ -0,0 +1,29 @@ +export const defaultHandler = async (req, res) => { + if (res.statusCode === 200) { + res.send({ message: 'Welcome to your default route...' }); + } +}; +export default { + name: 'routes-plugin', + hooks: { + fastify(gasket, app) { + {{#if useSwagger }} + /** + * @swagger + * + * /default: + * get: + * summary: "Get default route" + * produces: + * - "application/json" + * responses: + * "200": + * description: "Returns welcome message." + * content: + * application/json + */ + {{/if }} + app.get('/default', defaultHandler); + } + } +} diff --git a/packages/gasket-plugin-fastify/generator/app/routes/index.js b/packages/gasket-plugin-fastify/generator/app/routes/index.js deleted file mode 100644 index 69d01cf44..000000000 --- a/packages/gasket-plugin-fastify/generator/app/routes/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import gasket from '../gasket.js'; - -const app = gasket.actions.getFastifyApp(); - -export const defaultHandler = async (req, res) => { - if (res.statusCode === 200) { - res.send({ message: 'Welcome to your default route...' }); - } -}; - -{{#if useSwagger}} -/** -* @swagger -* -* /default: -* get: -* summary: "Get default route" -* produces: -* - "application/json" -* responses: -* "200": -* description: "Returns welcome message." -* content: -* application/json -*/ -{{/if}} -app.get('/default', defaultHandler); - diff --git a/packages/gasket-plugin-fastify/generator/app/routes/index.ts b/packages/gasket-plugin-fastify/generator/app/routes/index.ts deleted file mode 100644 index b3121bad2..000000000 --- a/packages/gasket-plugin-fastify/generator/app/routes/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { FastifyRequest, FastifyReply } from 'fastify'; -import gasket from '../gasket.js'; - -const app = gasket.actions.getFastifyApp(); - -export const defaultHandler = async (req: FastifyRequest, res: FastifyReply) => { - if (res.statusCode === 200) { - res.send({ message: 'Welcome to your default route...' }); - } -}; - -{{#if useSwagger}} -/** -* @swagger -* -* /default: -* get: -* summary: "Get default route" -* produces: -* - "application/json" -* responses: -* "200": -* description: "Returns welcome message." -* content: -* application/json -*/ -{{/if}} -app.get('/default', defaultHandler); - diff --git a/packages/gasket-plugin-fastify/generator/jest/test/index.test.js b/packages/gasket-plugin-fastify/generator/jest/test/index.test.js index afc4585a1..cb943cc6b 100644 --- a/packages/gasket-plugin-fastify/generator/jest/test/index.test.js +++ b/packages/gasket-plugin-fastify/generator/jest/test/index.test.js @@ -1,5 +1,5 @@ import { jest } from '@jest/globals'; -import { defaultHandler } from '../routes'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse; diff --git a/packages/gasket-plugin-fastify/generator/jest/test/index.test.ts b/packages/gasket-plugin-fastify/generator/jest/test/index.test.ts index b6e21033d..b0a5c4d64 100644 --- a/packages/gasket-plugin-fastify/generator/jest/test/index.test.ts +++ b/packages/gasket-plugin-fastify/generator/jest/test/index.test.ts @@ -5,7 +5,7 @@ import { it, expect } from '@jest/globals'; -import { defaultHandler } from '../routes'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse; diff --git a/packages/gasket-plugin-fastify/generator/mocha/test/index.test.js b/packages/gasket-plugin-fastify/generator/mocha/test/index.test.js index fa4d62f9b..ddaf74bd6 100644 --- a/packages/gasket-plugin-fastify/generator/mocha/test/index.test.js +++ b/packages/gasket-plugin-fastify/generator/mocha/test/index.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import sinon from 'sinon'; -import { defaultHandler } from '../routes/index.js'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse, sendSpy; diff --git a/packages/gasket-plugin-fastify/generator/mocha/test/index.test.ts b/packages/gasket-plugin-fastify/generator/mocha/test/index.test.ts index fa4d62f9b..ddaf74bd6 100644 --- a/packages/gasket-plugin-fastify/generator/mocha/test/index.test.ts +++ b/packages/gasket-plugin-fastify/generator/mocha/test/index.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import sinon from 'sinon'; -import { defaultHandler } from '../routes/index.js'; +import { defaultHandler } from '../plugins/routes-plugin.js'; describe('Routes', () => { let mockRequest, mockResponse, sendSpy; diff --git a/packages/gasket-plugin-fastify/lib/create-servers.js b/packages/gasket-plugin-fastify/lib/create-servers.js index 332a05170..61017b6b7 100644 --- a/packages/gasket-plugin-fastify/lib/create-servers.js +++ b/packages/gasket-plugin-fastify/lib/create-servers.js @@ -9,8 +9,17 @@ */ // eslint-disable-next-line max-statements module.exports = async function createServers(gasket, serverOpts) { - const app = gasket.actions.getFastifyApp(); + const fastify = require('fastify'); + const { alignLogger } = require('./utils'); + const { fastify: fastifyConfig = {}, http2, https } = gasket.config; + const { trustProxy = false, disableRequestLogging = true } = fastifyConfig; + const fastifyLogger = alignLogger(gasket.logger); + + // @ts-ignore + const app = fastify({ logger: fastifyLogger, trustProxy, https, http2, disableRequestLogging }); + // allow consuming apps to directly append options to their server + // @ts-ignore await gasket.exec('fastify', app); const postRenderingStacks = (await gasket.exec('errorMiddleware')).filter(Boolean); diff --git a/packages/gasket-plugin-fastify/lib/create.js b/packages/gasket-plugin-fastify/lib/create.js index 7001b9385..4cef0c6bc 100644 --- a/packages/gasket-plugin-fastify/lib/create.js +++ b/packages/gasket-plugin-fastify/lib/create.js @@ -55,6 +55,7 @@ module.exports = async function create(gasket, context) { if (apiApp && addApiRoutes) { const globIgnore = typescript ? '!(*.js)' : '!(*.ts)'; files.add(`${generatorDir}/app/**/${globIgnore}`); + gasketConfig.addPlugin('pluginRoutes', './plugins/routes-plugin.js'); createTestFiles({ files, generatorDir, testPlugins, globIgnore }); } diff --git a/packages/gasket-plugin-fastify/lib/index.d.ts b/packages/gasket-plugin-fastify/lib/index.d.ts index c6f2d01b1..775792c82 100644 --- a/packages/gasket-plugin-fastify/lib/index.d.ts +++ b/packages/gasket-plugin-fastify/lib/index.d.ts @@ -15,6 +15,7 @@ export type AppRoutes = Array void>>; declare module '@gasket/core' { export interface GasketActions { + /** @deprecated */ getFastifyApp(): FastifyInstance, FastifyBaseLogger, FastifyTypeProviderDefault>; } diff --git a/packages/gasket-plugin-fastify/lib/index.js b/packages/gasket-plugin-fastify/lib/index.js index f662f9a05..c3962a45a 100644 --- a/packages/gasket-plugin-fastify/lib/index.js +++ b/packages/gasket-plugin-fastify/lib/index.js @@ -19,6 +19,7 @@ const plugin = { version, description, actions: { + /** @deprecated */ getFastifyApp(gasket) { const { fastify: fastifyConfig = {}, http2, https } = gasket.config; const { trustProxy = false, disableRequestLogging = true } = fastifyConfig; @@ -40,7 +41,8 @@ const plugin = { { name: 'getFastifyApp', description: 'Get the Fastify app instance', - link: 'README.md#getFastifyApp' + link: 'README.md#getFastifyApp', + deprecated: true } ], lifecycles: [ diff --git a/packages/gasket-plugin-fastify/test/plugin.test.js b/packages/gasket-plugin-fastify/test/plugin.test.js index 78f45f1f4..c729826c0 100644 --- a/packages/gasket-plugin-fastify/test/plugin.test.js +++ b/packages/gasket-plugin-fastify/test/plugin.test.js @@ -49,7 +49,7 @@ describe('Plugin', function () { }); }); -describe('actions', () => { +describe('actions(deprecated)', () => { let gasket; beforeEach(() => { @@ -149,9 +149,6 @@ describe('createServers', () => { }; gasket = { - actions: { - getFastifyApp: jest.fn().mockReturnValue(app) - }, middleware: {}, logger: {}, config: { From b03736010c68506ab6f01f9fd682f2d142290441 Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Wed, 15 Jan 2025 13:52:57 -0800 Subject: [PATCH 3/4] presets: tune generated files --- packages/gasket-plugin-typescript/generator/shared/server.ts | 3 --- packages/gasket-preset-api/generator/server.js | 4 ---- 2 files changed, 7 deletions(-) diff --git a/packages/gasket-plugin-typescript/generator/shared/server.ts b/packages/gasket-plugin-typescript/generator/shared/server.ts index aef15afa2..2db355c92 100644 --- a/packages/gasket-plugin-typescript/generator/shared/server.ts +++ b/packages/gasket-plugin-typescript/generator/shared/server.ts @@ -1,9 +1,6 @@ // Imports use the .js to support a type module application // See README for more information import gasket from './gasket.js'; -{{#if apiApp }} -import './routes/index.js'; -{{/if}} {{#if nextDevProxy }} gasket.actions.startProxyServer(); {{else}} diff --git a/packages/gasket-preset-api/generator/server.js b/packages/gasket-preset-api/generator/server.js index 6ea37a5d0..a54b15ba0 100644 --- a/packages/gasket-preset-api/generator/server.js +++ b/packages/gasket-preset-api/generator/server.js @@ -1,6 +1,2 @@ import gasket from './gasket.js'; -{{#if apiApp }} -import './routes/index.js'; -{{/if}} - gasket.actions.startServer(); From 2fc9113f8a62851d6199baf7d8dea8db0f2f5076 Mon Sep 17 00:00:00 2001 From: Michael Mason Date: Wed, 15 Jan 2025 14:24:03 -0800 Subject: [PATCH 4/4] CHANGELOGS --- packages/gasket-plugin-express/CHANGELOG.md | 3 +++ packages/gasket-plugin-fastify/CHANGELOG.md | 3 +++ packages/gasket-plugin-typescript/CHANGELOG.md | 3 +++ 3 files changed, 9 insertions(+) diff --git a/packages/gasket-plugin-express/CHANGELOG.md b/packages/gasket-plugin-express/CHANGELOG.md index b71c02e2b..7d52c1b54 100644 --- a/packages/gasket-plugin-express/CHANGELOG.md +++ b/packages/gasket-plugin-express/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-express` +- Deprecate and remove the use of the `getExpressApp` action ([#1011]) + ### 7.1.3 - Adjust cookie parser invocation to earlier in the lifecycle chain ([#1009]) @@ -151,3 +153,4 @@ [#969]: https://github.com/godaddy/gasket/pull/969 [#1001]: https://github.com/godaddy/gasket/pull/1001 [#1009]: https://github.com/godaddy/gasket/pull/1009 +[#1011]: https://github.com/godaddy/gasket/pull/1011 diff --git a/packages/gasket-plugin-fastify/CHANGELOG.md b/packages/gasket-plugin-fastify/CHANGELOG.md index 8bd50120e..0bb532a1a 100644 --- a/packages/gasket-plugin-fastify/CHANGELOG.md +++ b/packages/gasket-plugin-fastify/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-fastify` +- Deprecate and remove the use of the `getFastifyApp` action ([#1011]) + ### 7.1.0 - Aligned version releases across all packages @@ -88,3 +90,4 @@ Enable middleware support ([#172]) [#940]: https://github.com/godaddy/gasket/pull/940 [#969]: https://github.com/godaddy/gasket/pull/969 [#972]: https://github.com/godaddy/gasket/pull/972 +[#1011]: https://github.com/godaddy/gasket/pull/1011 diff --git a/packages/gasket-plugin-typescript/CHANGELOG.md b/packages/gasket-plugin-typescript/CHANGELOG.md index 889f5043f..9fd797ef2 100644 --- a/packages/gasket-plugin-typescript/CHANGELOG.md +++ b/packages/gasket-plugin-typescript/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-typescript` +- Remove routes import from the `server.ts` ([#1011]) + ### 7.1.0 - Add HTTPS proxy server to Next.js dev server ([#982]) @@ -13,3 +15,4 @@ [Version 7 Upgrade Guide]: /docs/upgrade-to-7.md [#982]: https://github.com/godaddy/gasket/pull/982 +[#1011]: https://github.com/godaddy/gasket/pull/1011