6.46.8 • Published 3 days ago

@gasket/plugin-fastify v6.46.8

Weekly downloads
35
License
MIT
Repository
github
Last release
3 days ago

@gasket/plugin-fastify

Adds Fastify to your application.

Installation

New apps

gasket create <app-name> --plugins @gasket/plugin-fastify

Existing apps

npm i @gasket/plugin-fastify

Modify plugins section of your gasket.config.js:

module.exports = {
  plugins: [
    add: [
+      '@gasket/plugin-fastify'
    ]
  ]
}

Configuration

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

  • compression: true by default. Can to set to false if applying compression differently.
  • excludedRoutesRegex: Regex of the routes to exclude by Fastify.

Example configuration

module.exports = {
  plugins: {
    add: ['@gasket/fastify']
  },
  fastify: {
    compression: false,
    excludedRoutesRegex: /^(?!\/_next\/)/
  }
}

Lifecycles

middleware

Executed when the fastify server has been created, it will apply all returned functions as middleware.

module.exports = {
  hooks: {
    /**
    * Add Fastify middleware
    *
    * @param {Gasket} gasket The Gasket API
    * @param {Fastify} app - Fastify app instance
    * @returns {function|function[]} middleware(s)
    */
    middleware: function (gasket, app) {
      return require('x-xss-protection')();
    }
  }
}

You may also return an Array to inject more than one middleware.

fastify

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

module.exports = {
  hooks: {
    /**
    * Update Fastify app instance
    *
    * @param {Gasket} gasket The Gasket API
    * @param {Fastify} fastify Fastify app instance
    * @returns {function|function[]} middleware(s)
    */
    fastify: async function (gasket, fastify) {
    }
  }
}

errorMiddleware

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

module.exports = {
  hooks: {
    /**
    * Add Fastify 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

7.0.0-next.9

3 days ago

7.0.0-next.10

3 days ago

7.0.0-next.7

4 days ago

7.0.0-next.11

3 days ago

7.0.0-next.8

3 days ago

7.0.0-next.12

3 days ago

7.0.0-next.13

3 days ago

7.0.0-next.6

4 days ago

7.0.0-next.20

3 days ago

7.0.0-next.5

4 days ago

6.46.8

6 days ago

7.0.0-next.4

6 days ago

7.0.0-next.3

10 days ago

7.0.0-next.2

18 days ago

7.0.0-next.1

18 days ago

7.0.0-next.0

18 days ago

7.0.0-cli.7

1 month ago

7.0.0-cli.6

1 month ago

6.46.1-cli.0

2 months ago

7.0.0-cli.5

2 months ago

7.0.0-cli.4

2 months ago

7.0.0-cli.1

2 months ago

7.0.0-cli.0

2 months ago

7.0.0-cli.3

2 months ago

7.0.0-cli.2

2 months ago

6.46.3-cli.0

2 months ago

6.46.2

2 months ago

7.0.0-canary.1

2 months ago

6.46.2-esm.0

2 months ago

6.46.0

3 months ago

6.45.2

3 months ago

6.45.0

4 months ago

6.43.0

7 months ago

6.41.1

8 months ago

6.42.0-canary.1

8 months ago

6.42.0-canary.2

8 months ago

6.42.0-canary.0

8 months ago

6.39.3

11 months ago

6.39.0

11 months ago

6.38.8

12 months ago

6.38.5

1 year ago

6.38.2

1 year ago

6.38.1

1 year ago

6.36.1

1 year ago

6.38.0

1 year ago

6.34.6

2 years ago

6.36.0

1 year ago

6.34.3

2 years ago

6.34.4

2 years ago

6.34.2

2 years ago

6.33.0

2 years ago

6.33.1

2 years ago

6.26.1

2 years ago

6.28.0

2 years ago

6.21.0

2 years ago

6.24.2

2 years ago

6.24.0

2 years ago

6.20.4

2 years ago

6.20.3

2 years ago

6.20.2

2 years ago

6.19.0

2 years ago

6.10.1

2 years ago

6.10.0

2 years ago

6.14.0

2 years ago

6.17.0

2 years ago

6.15.2

2 years ago

6.0.12

3 years ago

6.0.5

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.0-canary.13

3 years ago

6.0.0-canary.0

4 years ago

5.6.0

4 years ago

5.1.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

5.0.0-canary.4

4 years ago

5.0.0-canary.3

4 years ago

5.0.0-canary.2

4 years ago

5.0.0-canary.1

4 years ago

5.0.0-canary.0

4 years ago