New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gasket/plugin-express

Package Overview
Dependencies
Maintainers
8
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gasket/plugin-express

Adds express support to your application

  • 7.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
8
Created
Source

@gasket/plugin-express

Adds Express to your application.

Guides

  • Setup Guide for adding middleware and routes.
  • Common "Gotchas" encountered with Express middleware.

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
  }
});

Route Definition

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.

// plugins/routes-plugin.js
export default {
  name: 'routes-plugin',
  hooks: {
    express: async function (gasket, app) {
      app.get('/hello', (req, res) => {
        res.send('Hello World!');
      });
    }
  }
};

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

Keywords

FAQs

Package last updated on 23 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc