@gasket/plugin-express
TypeScript icon, indicating that this package has built-in type declarations

7.0.14 • Public • Published

@gasket/plugin-express

Adds Express to your application.

Guides

Installation

npm i @gasket/plugin-express

Update your gasket file plugin configuration:

// gasket.js

+ import pluginExpress from '@gasket/plugin-express';

export default makeGasket({
  plugins: [
+   pluginExpress
  ]
});

Configuration

All the configurations for the plugin are added under express in the config:

  • compression: true by default. Can be set to false if applying compression differently.
  • excludedRoutesRegex: (deprecated) renamed to more correct middlewareInclusionRegex.
  • middlewareInclusionRegex: RegExp filter to apply toward request URLs to determine when Gasket middleware will run. You can use negative lookahead patterns to exclude routes like static resource paths.
  • 'trustProxy': Enable trust proxy option, see Express documentation on Express behind proxies

Example configuration

export default makeGasket({
  plugins: [
    pluginExpress
  ],
  express: {
    compression: false,
    middlewareInclusionRegex: /^(?!\/_next\/)/,
    trustProxy: true
  }
});

Actions

getExpressApp

Get the Express app instance.

const app = actions.gasket.getExpressApp();

Each Gasket creates a single shared Express instance, ensuring consistent access to the same app instance wherever it's needed.

Lifecycles

express

Executed after the middleware event for when you need full control over the express instance.

export default {
  name: 'sample-plugin',
  hooks: {
    /**
    * Update Express app instance
    *
    * @param {Gasket} gasket The Gasket API
    * @param {Express} express Express app instance
    * @returns {function|function[]} middleware(s)
    */
    express: async function (gasket, express) {
    }
  }
};

errorMiddleware

Executed after the express event. All middleware functions returned from this hook will be applied to Express.

export default {
  name: 'sample-plugin',
  hooks: {
    /**
    * Add Express error middlewares
    *
    * @param {Gasket} gasket The Gasket API
    * @returns {function|function[]} error middleware(s)
    */
    errorMiddleware: function (gasket) {
    }
  }
};

How it works

This plugins hooks the createServers lifecycles from @gasket/plugin-https.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @gasket/plugin-express

Weekly Downloads

461

Version

7.0.14

License

MIT

Unpacked Size

21.7 kB

Total Files

16

Last publish

Collaborators

  • bbetts
  • rxmarbles
  • ecarlson-godaddy
  • jpina1-godaddy
  • mmason2
  • kinetifex
  • 3rdeden
  • kawikabader