Skip to content

Commit

Permalink
update readme documents
Browse files Browse the repository at this point in the history
  • Loading branch information
bbetts-godaddy committed Jun 6, 2024
1 parent 342419f commit 800e827
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 103 deletions.
47 changes: 0 additions & 47 deletions packages/gasket-plugin-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,6 @@ module.exports = {
}
```

### Middleware paths

The `gasket.config.js` can contain a `middleware` property, which is an array of
objects that map plugins to route or path patterns, allowing apps to tune which
middleware are triggered for which requests.

```js
middleware: [
{
plugin:'gasket-plugin-example', // Name of the Gasket plugin
paths: ['/api']
},
{
plugin:'@some/gasket-plugin-example',
paths: [/\/default/]
},
{
plugin: '@another/gasket-plugin-example',
paths: ['/proxy', /\/home/]
}
]
```

## Logging

This plugin attaches a `logger` object to the request object. This object has a `metadata` method that allows you to attach details to any log entry related to the request. For example, you can add the user ID to each log entry. When logging within the context of a request, use the `req.logger` object instead of the global `gasket.logger` so that contextual information is included in the log entry. Here is an example of how to attach metadata to `req.logger` object and how to use it:
Expand All @@ -101,30 +78,6 @@ function someOtherMiddleware(req, res, next) {

## Lifecycles

### middleware

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

```js
module.exports = {
hooks: {
/**
* Add Express middleware
*
* @param {Gasket} gasket The Gasket API
* @param {Express} app - Express 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.

### express

Executed **after** the `middleware` event for when you need full control over
Expand Down
49 changes: 1 addition & 48 deletions packages/gasket-plugin-fastify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ All the configurations for the plugin are added under `fastify` in the config:

- `compression`: true by default. Can be set to false if applying compression
differently.
- `excludedRoutesRegex`: Routes to be excluded based on a regex
- `trustProxy`: Enable trust proxy option, [see Fastify documentation for possible values](https://fastify.dev/docs/latest/Reference/Server/#trustproxy)

#### Example configuration
Expand All @@ -46,61 +45,15 @@ module.exports = {
},
fastify: {
compression: false,
routes: 'api/*.js',
excludedRoutesRegex: /^(?!\/_next\/)/,
trustProxy: true
}
}
```

### Middleware paths

The `gasket.config.js` can contain a `middleware` property, which is an array of
objects that map plugins to route or path patterns, allowing apps to tune which
middleware are triggered for which requests.

```js
middleware: [
{
plugin:'gasket-plugin-example', // Name of the Gasket plugin
paths: ['/api']
},
{
plugin:'@some/gasket-plugin-example',
paths: [/\/default/]
},
{
plugin: '@another/gasket-plugin-example',
paths: ['/proxy', /\/home/]
}
]
```

## Lifecycles

### middleware

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

```js
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
Expand Down
92 changes: 84 additions & 8 deletions packages/gasket-plugin-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,91 @@ All the configurations for middleware setup are added under `express` or `fastif
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.
- `routes`: [Glob pattern](https://github.com/isaacs/node-glob#glob-primer) for source files exporting route-defining functions. These functions will be passed the express `app` object, and therein they can attach handlers and middleware.
- `trustProxy`: Enable trust proxy option, [Fastify trust proxy documentation](https://fastify.dev/docs/latest/Reference/Server/#trustproxy) or [Express trust proxy documentation](https://expressjs.com/en/guide/behind-proxies.html)
- `trustProxy`: Enable trust proxy option, [Fastify trust proxy documentation] or [Express trust proxy documentation]
- `routes`: for source files exporting route-defining functions. These functions will be passed the fastify `app` object, and therein they can attach handlers and middleware.

| Key | Description | Default | Fastify | Express |
| -------------- | ----------- | ------- | ------- | ------- |
| `compression ` | | true |||
| `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. | |||
| `routes` | Route-defining functions - these functions will be passed the `app` object, and therein they can attach handlers and middleware.
### Example Express configuration

```js
module.exports = {
plugins: {
add: ['@gasket/plugin-express', '@gasket/plugin-middleware']
},
express: {
compression: false,
routes: 'api/*.js',
middlewareInclusionRegex: /^(?!\/_next\/)/,
trustProxy: true
}
}
```

### Example Fastify configuration

```js
module.exports = {
plugins: {
add: ['@gasket/fastify', '@gasket/plugin-middleware']
},
fastify: {
compression: false,
routes: 'api/*.js',
middlewareInclusionRegex: /^(?!\/_next\/)/,
trustProxy: true
}
}
```

## Middleware paths

The `gasket.config.js` can contain a `middleware` property, which is an array of
objects that map plugins to route or path patterns, allowing apps to tune which
middleware are triggered for which requests.

```js
middleware: [
{
plugin:'gasket-plugin-example', // Name of the Gasket plugin
paths: ['/api']
},
{
plugin:'@some/gasket-plugin-example',
paths: [/\/default/]
},
{
plugin: '@another/gasket-plugin-example',
paths: ['/proxy', /\/home/]
}
]
```

## Lifecycles

### middleware

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

```js
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.

<!-- LINKS -->

[Fastify trust proxy documentation]:https://fastify.dev/docs/latest/Reference/Server/#trustproxy
[Express trust proxy documentation]:https://expressjs.com/en/guide/behind-proxies.html

0 comments on commit 800e827

Please sign in to comment.