### Install and Run API Locally Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-preset-api/generator/README.md Navigate to the project directory, install dependencies, and start the API locally. ```bash cd {{{appName}}} {{{installCmd}}} {{{localCmd}}} ``` -------------------------------- ### Install and Run Application Locally Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-template-api-express/template/README.md Navigate to the application directory, install dependencies, and start the API locally. ```bash cd {{{appName}}} npm install npm run local ``` -------------------------------- ### Start Gasket Application Locally Source: https://github.com/godaddy/gasket/blob/main/packages/create-gasket-app/test/fixtures/packages/ci-basic-plugin/generator/README.md Navigate to the application directory, install dependencies, and start the Gasket app. This assumes you have the necessary install and local commands defined. ```bash cd {{{appName}}} {{{installCmd}}} {{{localCmd}}} ``` -------------------------------- ### Installation and Basic Configuration Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-nextjs/README.md Instructions for installing the plugin and updating your gasket.js file, along with an example of basic Next.js configuration. ```APIDOC ## Installation ```bash npm i @gasket/plugin-nextjs ``` Update your `gasket.js` file plugin configuration: ```diff // gasket.js import pluginNextjs from '@gasket/plugin-nextjs'; export default makeGasket({ plugins: [ pluginNextjs ] }); ``` ## Configuration It is also possible for apps to config Next.js using the `gasket.js` file. To do so, specify a `nextConfig` object property in the same form as what you would set for [custom configurations][next.config] or using Next.js plugins. #### Example Gasket configuration ```js // gasket.js export default makeGasket({ plugins: [ pluginNextjs ], nextConfig: { poweredByHeader: false, useFileSystemPublicRoutes: false } }); ``` ``` -------------------------------- ### Basic Plugin Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-winston/EXAMPLES.md Install the plugin by importing it and adding it to the plugins array in your gasket.js configuration. ```javascript import { makeGasket } from '@gasket/core'; import pluginWinston from '@gasket/plugin-winston'; export default makeGasket({ plugins: [ pluginWinston ] }); ``` -------------------------------- ### Basic Plugin Installation and Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-workbox/EXAMPLES.md Configure the basic @gasket/plugin-workbox by importing and including it in your gasket configuration. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginWorkbox from '@gasket/plugin-workbox'; export default makeGasket({ plugins: [ pluginWorkbox ] }); ``` -------------------------------- ### Gasket Plugin: Init Lifecycle Example Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-core/README.md Example of a Gasket plugin implementing the `init` lifecycle. This hook is executed early for initial setup and can record timestamps. ```javascript // gasket-plugin-example.js const name = 'gasket-plugin-example'; let _initializedTime; const hooks = { init(gasket) { _initializedTime = Date.now(); } }; export default { name, hooks }; ``` -------------------------------- ### Install and Setup @gasket/plugin-happyfeet Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-happyfeet/EXAMPLES.md Demonstrates how to import and include the plugin in your Gasket application's configuration. ```javascript import { makeGasket } from '@gasket/core'; import pluginHappyfeet from '@gasket/plugin-happyfeet'; export default makeGasket({ plugins: [ pluginHappyfeet ] }); ``` -------------------------------- ### Installation and Basic Configuration Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-webpack/README.md Instructions on how to install the plugin and add it to your Gasket configuration. ```APIDOC ## Installation ```sh npm i @gasket\/plugin-webpack ``` Update your `gasket` file plugin configuration: ```diff // gasket.js + import pluginWebpack from '@gasket\/plugin-webpack'; export default makeGasket({ plugins: [ + pluginWebpack ] }); ``` ## Configuration The Webpack plugin is configured using the `gasket.js` file. First, add it to the `plugins` section of your `gasket.js`: ```js export default makeGasket({ plugins: { pluginWebpack } }); ``` If your app was previously using the `webpack` property in the `gasket.js`, you should update your configuration to use the [webpackConfig] lifecycle instead. ``` -------------------------------- ### Build and Start Application Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-template-api-express/template/README.md Run the build and start scripts together to compile and then run the application. ```bash npm run preview ``` -------------------------------- ### Install Dependencies Source: https://github.com/godaddy/gasket/blob/main/site/README.md Run this command to install project dependencies. ```bash yarn ``` -------------------------------- ### Build and Start Gasket App Source: https://github.com/godaddy/gasket/blob/main/docs/quick-start.md To prepare the application for production or a standalone deployment, first build the application and then start it using `npm run build` and `npm run start` respectively. ```bash npm run build ``` ```bash npm run start ``` -------------------------------- ### Basic Plugin Installation Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-docusaurus/EXAMPLES.md Install the plugin by importing it in your gasket.js file. ```javascript import { makeGasket } from '@gasket/core'; import pluginDocs from '@gasket/plugin-docs'; import pluginDocusaurus from '@gasket/plugin-docusaurus'; export default makeGasket({ plugins: [ pluginDocs, pluginDocusaurus ] }); ``` -------------------------------- ### Basic Plugin Installation Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-https/EXAMPLES.md Demonstrates how to install the @gasket/plugin-https plugin with basic Gasket configuration. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginHttps from '@gasket/plugin-https'; export default makeGasket({ plugins: [ pluginHttps ] }); ``` -------------------------------- ### Define Custom Docs Setup in Gasket Preset Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-docs/README.md This example demonstrates how to configure custom documentation settings within a Gasket preset using the `docsSetup` property. It specifies a link to another markdown file and includes glob patterns for additional documentation files. ```javascript // gasket-preset-example.js export default { name: 'gasket-preset-example', docsSetup: { link: 'OTHER.md#go-here', files: ['more-docs/**/*.*'], } } ``` -------------------------------- ### Basic Plugin Setup with @gasket/plugin-fastify Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-fastify/EXAMPLES.md Demonstrates the basic setup for integrating the @gasket/plugin-fastify plugin into a Gasket application. ```javascript import { makeGasket } from '@gasket/core'; import pluginFastify from '@gasket/plugin-fastify'; export default makeGasket({ plugins: [ pluginFastify ] }); ``` -------------------------------- ### Install @gasket/plugin-docs-graphs Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-docs-graphs/README.md Use npm to install the plugin. This is the first step before configuring it. ```bash npm i @gasket/plugin-docs-graphs ``` -------------------------------- ### Install @gasket/plugin-morgan Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-morgan/EXAMPLES.md Basic installation of the plugin. Ensure @gasket/plugin-express is also included. ```javascript import { makeGasket } from '@gasket/core'; import pluginMorgan from '@gasket/plugin-morgan'; import pluginExpress from '@gasket/plugin-express'; export default makeGasket({ plugins: [ pluginExpress, pluginMorgan ] }); ``` -------------------------------- ### Preboot Hook for HTTPS Proxy Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-https-proxy/EXAMPLES.md Implement custom logic to run before the HTTPS proxy server starts. This hook is useful for tasks like loading SSL certificates, initializing connection pools, or setting up health checks. ```javascript export default { name: 'my-proxy-plugin', hooks: { prebootHttpsProxy: async function(gasket) { // Load SSL certificates gasket.logger.info('Loading SSL certificates...'); await loadCertificates(); // Initialize connection pools gasket.logger.info('Initializing connection pools...'); await initializeConnectionPools(); // Set up health check endpoints gasket.logger.info('Setting up health checks...'); await setupHealthChecks(); } } }; async function loadCertificates() { // Certificate loading logic return new Promise(resolve => setTimeout(resolve, 100)); } async function initializeConnectionPools() { // Connection pool initialization return new Promise(resolve => setTimeout(resolve, 50)); } async function setupHealthChecks() { // Health check setup return new Promise(resolve => setTimeout(resolve, 25)); } ``` -------------------------------- ### Installation Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-cjs/README.md Install the @gasket/cjs package using pnpm. ```APIDOC ## Installation ```bash pnpm install @gasket/cjs ``` ``` -------------------------------- ### Basic Plugin Installation Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-command/EXAMPLES.md Install and configure the command plugin in your Gasket application. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginCommand from '@gasket/plugin-command'; export default makeGasket({ plugins: [ pluginCommand ] }); ``` -------------------------------- ### Install @gasket/fetch Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-fetch/README.md Install the @gasket/fetch package using npm. ```bash npm i @gasket/fetch ``` -------------------------------- ### Install @gasket/plugin-dynamic-plugins Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-dynamic-plugins/README.md Install the plugin using npm. ```bash npm i @gasket/plugin-dynamic-plugins ``` -------------------------------- ### Install @gasket/plugin-analyze Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-analyze/README.md Install the plugin using npm. Then, import and add it to your gasket.js plugin configuration. ```bash npm i @gasket/plugin-analyze ``` ```diff // gasket.js + import pluginAnalyze from '@gasket/plugin-analyze'; export default makeGasket({ plugins: [ + pluginAnalyze ] }); ``` -------------------------------- ### Install @gasket/plugin-manifest Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-manifest/README.md Install the plugin using npm. This is the first step for new applications. ```bash npm i @gasket/plugin-manifest ``` -------------------------------- ### Install @gasket/plugin-redux and @gasket/plugin-middleware Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-redux/README.md Install the necessary Gasket plugins using npm. ```bash npm i @gasket/plugin-redux @gasket/plugin-middleware ``` -------------------------------- ### Example Test File Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-vitest/EXAMPLES.md A basic example of a Vitest test file that can be generated by the plugin. ```javascript // test/example.test.js import { describe, it, expect } from 'vitest'; describe('Example test', () => { it('should pass', () => { expect(true).toBe(true); }); }); ``` -------------------------------- ### Install @gasket/core Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-core/README.md Install the core Gasket package using npm. This is the first step for existing applications. ```shell npm install @gasket/core ``` -------------------------------- ### Install @gasket/plugin-data Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-data/README.md Install the plugin using npm. This is the first step for new applications. ```bash npm i @gasket/plugin-data ``` -------------------------------- ### Basic Plugin Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-swagger/EXAMPLES.md Configure the plugin with a definition file and API docs route. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginSwagger from '@gasket/plugin-swagger'; export default makeGasket({ plugins: [ pluginSwagger ], swagger: { definitionFile: 'swagger.json', apiDocsRoute: '/api-docs' } }); ``` -------------------------------- ### GET /users Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-swagger/EXAMPLES.md Example of documenting a basic GET endpoint to retrieve all users using JSDoc annotations. ```APIDOC ## GET /users ### Description This endpoint retrieves a list of all users. The response is documented to be an array of user objects. ### Method GET ### Endpoint /users ### Parameters None ### Request Body None ### Response #### Success Response (200) - **description** (string) - List of users - **content** (object) - **application/json** (object) - **schema** (object) - **type** (string) - array - **items** (object) - **$ref** (string) - '#/components/schemas/User' ### Response Example ```json [ { "id": "user-123", "email": "user@example.com", "name": "John Doe", "createdAt": "2023-01-01T12:00:00Z" } ] ``` ### Code ```javascript // routes/users.js /** * @swagger * /users: * get: * summary: Get all users * tags: [Users] * responses: * 200: * description: List of users * content: * application/json: * schema: * type: array * items: * $ref: '#/components/schemas/User' */ router.get('/users', (req, res) => { res.json([]); }); ``` ``` -------------------------------- ### Install pnpm Source: https://github.com/godaddy/gasket/blob/main/CONTRIBUTING.md Instructions for installing pnpm, the package manager used in this monorepo. ```bash pnpm install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/godaddy/gasket/blob/main/site/README.md Starts a local development server for live preview. Changes are reflected without a server restart. ```bash yarn start ``` -------------------------------- ### Install @gasket/plugin-middleware Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-middleware/README.md Install the plugin using npm. This is the initial step for integrating middleware functionality. ```sh npm i @gasket/plugin-middleware ``` -------------------------------- ### Install @gasket/plugin-morgan Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-morgan/README.md Install the plugin using npm. This is the first step to integrating morgan logging into your Gasket application. ```bash npm i @gasket/plugin-morgan ``` -------------------------------- ### GET /users/{id} Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-swagger/EXAMPLES.md Example of documenting a GET endpoint to retrieve a specific user by ID, including path parameters and error responses. ```APIDOC ## GET /users/{id} ### Description This endpoint retrieves a specific user's details by their unique ID. It includes documentation for path parameters and potential error responses like 404 Not Found. ### Method GET ### Endpoint /users/{id} ### Parameters #### Path Parameters - **id** (string) - Required - User ID ### Request Body None ### Response #### Success Response (200) - **description** (string) - User details - **content** (object) - **application/json** (object) - **schema** (object) - **$ref** (string) - '#/components/schemas/User' #### Error Response (404) - **description** (string) - User not found ### Response Example ```json { "id": "user-123", "email": "user@example.com", "name": "John Doe", "createdAt": "2023-01-01T12:00:00Z" } ``` ### Code ```javascript // routes/users.js /** * @swagger * /users/{id}: * get: * summary: Get user by ID * tags: [Users] * parameters: * - in: path * name: id * required: true * schema: * type: string * description: User ID * responses: * 200: * description: User details * content: * application/json: * schema: * $ref: '#/components/schemas/User' * 404: * description: User not found */ router.get('/users/:id', (req, res) => { res.json({}); }); ``` ``` -------------------------------- ### Basic Plugin Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-swagger/EXAMPLES.md Demonstrates the minimal configuration required to enable the swagger plugin. ```APIDOC ## Plugin Configuration: Basic Plugin Setup ### Description This snippet shows the basic setup for the `@gasket/plugin-swagger` in your `gasket.js` file. ### Code ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginSwagger from '@gasket/plugin-swagger'; export default makeGasket({ plugins: [ pluginSwagger ], swagger: { definitionFile: 'swagger.json', apiDocsRoute: '/api-docs' } }); ``` ``` -------------------------------- ### Start Development Server with GASKET_DEV Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-nextjs/EXAMPLES.md Set the `GASKET_DEV=1` environment variable to start the development server when using a custom server setup. This is typically used with `npm run local`. ```bash # Start development server when using Custom Server GASKET_DEV=1 npm run local ``` -------------------------------- ### Install @gasket/plugin-docs Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-docs/README.md Install the plugin using npm. Then, update your gasket.js file to include the plugin in the plugins array. ```bash npm i @gasket/plugin-docs ``` ```diff // gasket.js + import pluginDocs from '@gasket/plugin-docs'; export default makeGasket({ plugins: [ + pluginDocs ] }); ``` -------------------------------- ### Basic Gasket Plugin Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-middleware/EXAMPLES.md Demonstrates the basic setup for a Gasket application by importing and registering core plugins like Express and Middleware. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginMiddleware from '@gasket/plugin-middleware'; import pluginExpress from '@gasket/plugin-express'; export default makeGasket({ plugins: [ pluginExpress, pluginMiddleware ] }); ``` -------------------------------- ### Add Custom Server Entry Point Source: https://github.com/godaddy/gasket/blob/main/docs/upgrade-to-7.md Create a server.js file to initiate the Gasket server with Next.js. ```js import gasket from './gasket.js'; gasket.actions.startServer(); ``` -------------------------------- ### Get Logger Instance using Action Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-logger/EXAMPLES.md Retrieve the logger instance that was initialized during Gasket setup using the getLogger action. ```javascript // Using the action const logger = gasket.actions.getLogger(); logger.info('Application started'); logger.error('Something went wrong'); ``` -------------------------------- ### Basic Plugin Setup Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-webpack/EXAMPLES.md Set up the Gasket core with the webpack plugin. ```javascript import { makeGasket } from '@gasket/core'; import pluginWebpack from '@gasket/plugin-webpack'; export default makeGasket({ plugins: [ pluginWebpack ] }); ``` -------------------------------- ### Combine Locale and Message Providers Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-nextjs/EXAMPLES.md This example shows how to combine `withLocaleInitialProps` with `withMessagesProvider` and `IntlProvider` for comprehensive internationalization setup in `_app.js`. ```jsx // pages/_app.js import { withLocaleInitialProps } from '@gasket/nextjs'; import { withMessagesProvider } from '@gasket/react-intl'; import { IntlProvider } from 'react-intl'; import intlManager from '../path/to/intl.js'; import gasket from '../gasket.js'; const IntlMessagesProvider = withMessagesProvider(intlManager)(IntlProvider); function MyApp({ Component, pageProps, locale }) { return ( ); } export default withLocaleInitialProps(gasket)(MyApp); ``` -------------------------------- ### Generated server.ts for Custom Server or Proxy Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-typescript/EXAMPLES.md Example of a generated `server.ts` file, showing import conventions and how to start the server or proxy. ```typescript // Imports use the .js to support a type module application // See README for more information import gasket from './gasket.js'; gasket.actions.startServer(); // Or for proxy server configuration: // gasket.actions.startProxyServer(); ``` -------------------------------- ### Server-side IntlManager Usage Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-intl/EXAMPLES.md Example of using IntlManager on the server-side to get supported locales, resolve locales, and handle specific locale files. ```javascript // Server-side usage import gasket from './gasket.js'; async function setupLocalization() { const intlManager = await gasket.actions.getIntlManager(); // Get supported locales const supportedLocales = intlManager.locales; console.log('Supported locales:', supportedLocales); // Resolve a locale const resolvedLocale = intlManager.resolveLocale('fr-CA'); console.log('Resolved locale:', resolvedLocale); // 'fr-FR' if fr-CA maps to fr-FR // Handle a specific locale const localeHandler = intlManager.handleLocale('en-US'); await localeHandler.loadStatics(); return { manager: intlManager, handler: localeHandler }; } ``` -------------------------------- ### Action for Getting a Singleton Instance Source: https://github.com/godaddy/gasket/blob/main/docs/gasket-actions.md Actions can manage and return singleton instances. This example demonstrates creating a singleton if it doesn't exist and returning it. ```javascript // Action code let singleton; const actions = { getSingleton() { if (!singleton) { singleton = { doSomething() { // do something } }; } return singleton; } }; // Application code const singleton = gasket.actions.getSingleton(); singleton.doSomething(); ``` -------------------------------- ### Run Development Server Source: https://github.com/godaddy/gasket/blob/main/packages/create-gasket-app/test/__mocks__/@gasket/template-test/template/README.md Use this command to start the development server for the test application. Access the application at http://localhost:3000 in your browser. ```bash npm run dev ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/godaddy/gasket/blob/main/site/blog/2020-12-10-api-preset/2020-12-10-api-preset.md After the project is created, change into the new project directory to access its files and begin development. ```bash cd fingerstache-coffee ``` -------------------------------- ### Gasket Readiness Check Source: https://github.com/godaddy/gasket/blob/main/docs/upgrade-to-7.md Example of checking Gasket's readiness using the 'gasket.isReady' promise before executing asynchronous actions like starting the server. ```javascript import gasket from './gasket.js'; gasket.isReady.then(() => { gasket.actions.startServer(); }); ``` -------------------------------- ### Create API Route in Next.js Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-template-nextjs-express/README.md Add API routes in the `pages/api/` directory using Next.js. This example shows a basic GET request handler. ```tsx // pages/api/users.ts import type { NextApiRequest, NextApiResponse } from 'next'; export default function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === 'GET') { res.status(200).json({ users: [] }); } else { res.setHeader('Allow', ['GET']); res.status(405).end(`Method ${req.method} Not Allowed`); } } ``` -------------------------------- ### Configure Node.js start script Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-elastic-apm/README.md Add NODE_OPTIONS=--import=./setup.js to your package.json start script to ensure the APM agent is loaded early. ```diff "scripts": { "build": "next build", - "start": "next start", + "start": "NODE_OPTIONS=--import=./setup.js next start", "local": "next dev" } ``` -------------------------------- ### preboot Lifecycle Hook Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-https/README.md Implement asynchronous operations before the server starts. This hook is ideal for setup tasks that must complete prior to server initialization. ```js /** * Executed before the server is started. * * @param {Gasket} gasket Gasket API. */ preboot: async function preboot(gasket) { // async operations } ``` -------------------------------- ### Define Express Routes in a Plugin Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-express/README.md Define routes for your Express application within an in-app plugin. This example adds a '/hello' GET route that responds with 'Hello World!'. ```javascript // plugins/routes-plugin.js export default { name: 'routes-plugin', hooks: { express: async function (gasket, app) { app.get('/hello', (req, res) => { res.send('Hello World!'); }); } } }; ``` -------------------------------- ### Gasket Data Usage in Pages Router Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-nextjs/EXAMPLES.md Access Gasket data within a page component in a Pages Router setup. This example demonstrates using `useGasketData` and `withLocaleInitialProps`. ```jsx // pages/index.js import { useGasketData } from '@gasket/nextjs'; import { withLocaleInitialProps } from '@gasket/nextjs'; import gasket from '../gasket.js'; function HomePage({ locale }) { const gasketData = useGasketData(); return (

Welcome to {gasketData.appName}

Locale: {locale}

); } export default withLocaleInitialProps(gasket)(HomePage); ``` -------------------------------- ### Conditionally get APM transaction Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-elastic-apm/README.md Conditionally invoke getApmTransaction within express middleware, for example, to only decorate non-API requests, ensuring the APM transaction lifecycle is executed when needed. ```javascript export default { name: 'example-plugin', hooks: { express(gasket, app) { app.use(async (req, res, next) => { // Only decorate APM transaction for non-API requests if(!req.path.startsWith('/api')) { await gasket.actions.getApmTransaction(req); } next(); }); } } } ``` -------------------------------- ### Example morgan configuration Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-morgan/README.md Configure the log format and morgan options within the 'morgan' section of your Gasket configuration. Defaults to 'tiny' format with empty options. ```javascript export default makeGasket({ plugins: { pluginMorgan }, morgan: { format: 'tiny', options: {} } }); ``` -------------------------------- ### Define Express Routes with Local Plugin Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-express/generator/app/plugins/README.md Use a local plugin to define Express routes. This plugin hooks into the `express` lifecycle to mutate the Express app. The example shows a GET route available at `/default`. ```javascript GET /default ``` -------------------------------- ### Basic Plugin Setup with @gasket/plugin-metadata Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-metadata/EXAMPLES.md Demonstrates how to include the plugin-metadata plugin in your Gasket application. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginMetadata from '@gasket/plugin-metadata'; export default makeGasket({ plugins: [ pluginMetadata ] }); ``` -------------------------------- ### Sample API Route Definition Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-template-api-express/README.md Define API routes within the `plugins/routes-plugin.ts` file using the `express` lifecycle hook. This example demonstrates how to add a GET endpoint for '/users' and includes JSDoc comments for Swagger documentation generation. ```typescript export default { name: 'routes-plugin', hooks: { express(gasket, app) { /** * @swagger * /users: * get: * summary: Get all users * responses: * 200: * description: List of users */ app.get('/users', (req, res) => { res.json({ users: [] }); }); } } }; ``` -------------------------------- ### Start Gasket Server Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-https/README.md Initiate the Gasket application server by calling the `startServer` action. This should typically be placed in a `server.js` file. ```js import gasket from './gasket.js'; gasket.actions.startServer(); ``` -------------------------------- ### Add Custom Routes with Fastify Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-nextjs/EXAMPLES.md Use the `nextFastify` hook to integrate custom Fastify routes and render Next.js pages. This example demonstrates adding a POST endpoint for data processing and a GET endpoint for rendering a special page. ```javascript export default { name: 'fastify-api-plugin', hooks: { nextFastify(gasket, { next, fastify }) { // Add Fastify routes fastify.post('/api/data', async (request, reply) => { return { data: 'processed' }; }); // Render Next.js pages fastify.get('/special/:id', async (request, reply) => { await next.render(request.raw, reply.raw, '/special-page', { id: request.params.id }); }); } } }; ``` -------------------------------- ### Add Custom API Routes with Express Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-nextjs/EXAMPLES.md The `nextExpress` hook allows you to integrate custom Express routes and programmatically render Next.js pages. This example adds a POST endpoint for webhooks and a GET endpoint for rendering a custom page. ```javascript export default { name: 'api-routes-plugin', hooks: { nextExpress(gasket, { next, express }) { // Add custom API routes express.post('/api/webhook', (req, res) => { // Process webhook res.json({ received: true }); }); // Render Next.js pages programmatically express.get('/custom-page/:id', (req, res) => { return next.render(req, res, '/dynamic-page', { id: req.params.id }); }); } } }; ``` -------------------------------- ### Basic Plugin Setup with Manifest Configuration Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-manifest/EXAMPLES.md Configure the plugin-manifest with basic web app manifest properties like name, short_name, and icons. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginManifest from '@gasket/plugin-manifest'; export default makeGasket({ plugins: [ pluginManifest ], manifest: { short_name: 'MyApp', name: 'My Progressive Web Application', description: 'A demo PWA built with Gasket', start_url: '/', display: 'standalone', theme_color: '#000000', background_color: '#ffffff', icons: [ { src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' } ] } }); ``` -------------------------------- ### Sample API Route Definition in Gasket Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-template-api-fastify/README.md Define API routes within the `plugins/routes-plugin.ts` file using Fastify's lifecycle hooks. This example shows how to add a GET endpoint for '/users' and includes JSDoc comments for Swagger documentation generation. ```typescript export default { name: 'routes-plugin', hooks: { fastify(gasket, app) { /** * @swagger * /users: * get: * summary: Get all users * responses: * 200: * description: List of users */ app.get('/users', async (req, res) => { res.send({ users: [] }); }); } } }; ``` -------------------------------- ### Install Production Dependencies Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-nextjs/docs/deployment.md Use the --production flag with npm install to only install dependencies required for the production environment, speeding up installation. ```bash npm install --production ``` -------------------------------- ### Build and Run Gasket Preview Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-typescript/generator/markdown/README.md Combines the build and start scripts for a preview of the compiled application. This is useful for testing the final output. ```bash {{{packageManager}}} run preview ``` -------------------------------- ### Install @gasket/react-intl Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-react-intl/README.md Install the package using npm. ```bash npm i @gasket/react-intl ``` -------------------------------- ### Setup Elastic APM agent Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-elastic-apm/README.md Create a setup.js file to initialize the Elastic APM agent with essential configuration like serviceName, captureHeaders, secretToken, and serverUrl. ```javascript // setup.js import apm from 'elastic-apm-node'; // Elastic APM setup apm.start({ serviceName: 'my-service-name', captureHeaders: false, secretToken: process.env.ELASTIC_APM_SECRET_TOKEN, serverUrl: process.env.ELASTIC_APM_SERVER_URL // additional configuration options }); ``` -------------------------------- ### Basic Plugin Setup with @gasket/plugin-docs Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-docs/EXAMPLES.md Configure basic plugin setup for @gasket/plugin-docs in your gasket.js file. This includes importing the plugin and setting the output directory. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginDocs from '@gasket/plugin-docs'; export default makeGasket({ plugins: [ pluginDocs ], docs: { outputDir: '.docs' // Default } }); ``` -------------------------------- ### Install @gasket/assets Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-assets/README.md Install the package using npm. ```bash npm i @gasket/assets ``` -------------------------------- ### Basic Plugin Installation Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-analyze/EXAMPLES.md Install the plugin by importing it in your gasket.js file. The analyzer only runs when ANALYZE is set or using a .analyze sub-environment. ```javascript import { makeGasket } from '@gasket/core'; import pluginAnalyze from '@gasket/plugin-analyze'; export default makeGasket({ plugins: [ pluginAnalyze ] }); ``` -------------------------------- ### npm Preview Script Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-typescript/EXAMPLES.md Example of the `preview` script for npm package manager. ```json { "scripts": { "preview": "npm run build && npm run start" } } ``` -------------------------------- ### Gasket Guides Source: https://github.com/godaddy/gasket/blob/main/README.md Documentation and guides for Gasket framework. ```APIDOC ## Guides ### Description Help and explanations docs ### Available Guides - **Quick Start Guide**: Get up and running on Gasket - **Upgrades Guide**: Steps necessary to upgrade major versions - **Gasket Actions Guide**: How to use access data and invoke lifecycles - **Intl Quick Start Guide**: Add internationalization to your app - **Express Setup Guide**: Adding middleware and routes for Express - **Next.js Routing Guide**: Basic and advance routing for Next.js - **Next.js Deployment Guide**: Steps to deploy a Next.js Gasket app - **Webpack Configuration Guide**: Configuring Webpack in Gasket apps ``` -------------------------------- ### Start Gasket App with Debugging Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-preset-nextjs/generator/README.md To enable debugging for the API locally, prefix the local start command with DEBUG=*. This allows for detailed logging of all operations. ```bash DEBUG=* {{{localCmd}}} ``` -------------------------------- ### Install @gasket/utils Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-utils/README.md Install the @gasket/utils package using npm. ```bash npm i @gasket/utils ``` -------------------------------- ### Create Gasket App with Git Initialization Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-git/EXAMPLES.md Use these commands to create a new Gasket app. The first command will prompt for Git initialization, while the second forces it via configuration. ```bash npx create-gasket-app@latest my-app --presets @gasket/preset-api ``` ```bash npx create-gasket-app@latest my-app --presets @gasket/preset-api --config '{"gitInit": true}' ``` -------------------------------- ### Install @gasket/redux Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-redux/README.md Install the @gasket/redux package using npm. ```bash npm i @gasket/redux ``` -------------------------------- ### Add Plugins and Configuration with presetConfig Source: https://github.com/godaddy/gasket/blob/main/docs/authoring-presets.md This example demonstrates how to add plugins and custom configuration within the presetConfig hook. The returned object includes a plugins array and additional properties that will be merged into the Gasket object. ```javascript // my-preset/preset-config.js import pluginFoo from '@gasket/plugin-foo'; import pluginBar from '@gasket/plugin-bar'; export default async function presetConfig(gasket, context) { const myConfigObject = { my: 'value' } return { additionalProperty: myConfigObject, plugins: [ pluginFoo pluginBar ] }; } ``` ```javascript // Generated gasket.js file import pluginFoo from '@gasket/plugin-foo'; import pluginBar from '@gasket/plugin-bar'; export default makeGasket({ plugins: [ pluginFoo, pluginBar ], additionalProperty: { my: 'value' } }); ``` -------------------------------- ### Initialize Gasket with Data Plugin Source: https://context7.com/godaddy/gasket/llms.txt Set up the Gasket application by importing necessary plugins and providing the environment data configuration. The `plugin-data` is essential for managing Gasket data. ```javascript // gasket.js import { makeGasket } from '@gasket/core'; import pluginData from '@gasket/plugin-data'; import gasketData from './gasket-data.js'; export default makeGasket({ plugins: [pluginData], data: gasketData }); ``` -------------------------------- ### Install @gasket/nextjs Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-nextjs/README.md Install the @gasket/nextjs package using npm. ```bash npm i @gasket/nextjs ``` -------------------------------- ### Async Middleware Initialization Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-middleware/EXAMPLES.md Illustrates creating middleware that requires asynchronous initialization, such as establishing a database connection, before being applied. ```javascript // database-plugin.js export default { name: 'database-plugin', hooks: { async middleware(gasket, app) { const dbConnection = await initializeDatabase(); return (req, res, next) => { req.db = dbConnection; next(); }; } } }; ``` -------------------------------- ### Install @gasket/cjs Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-cjs/README.md Install the @gasket/cjs package using pnpm. ```bash pnpm install @gasket/cjs ``` -------------------------------- ### Install @gasket/data Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-data/README.md Install the @gasket/data package using npm. ```bash npm i @gasket/data ``` -------------------------------- ### Start HTTPS Proxy Server Action Source: https://github.com/godaddy/gasket/blob/main/packages/gasket-plugin-https-proxy/README.md Use the startProxyServer action to initiate the HTTPS proxy server. This action ensures that Gasket is ready and executes necessary lifecycle hooks before starting the server. ```javascript import gasket from './gasket.js'; gasket.actions.startProxyServer(); ``` -------------------------------- ### Navigate to App Directory Source: https://github.com/godaddy/gasket/blob/main/docs/quick-start.md After creating the app, change into the newly generated application directory to proceed with development. ```bash cd ./your-app-name ``` -------------------------------- ### Update ElasticAPM Start Script Source: https://github.com/godaddy/gasket/blob/main/docs/upgrade-to-7.md Modifies the 'start' script to use the 'NODE_OPTIONS' environment variable for starting the ElasticAPM agent, replacing the deprecated Gasket CLI approach. ```diff "scripts": { - "start": "gasket start --require elastic-apm-node/start", + "start": "NODE_OPTIONS=--import=./setup.js next start", } ```