network-error-logging
Version:
NEL Middleware for Express
36 lines (27 loc) • 2.31 kB
Markdown
Network Error Logging
==============
[](https://badge.fury.io/js/network-error-logging)
[](https://david-dm.org/Cherry/network-error-logging)
[](https://github.com/Cherry/network-error-logging/actions)
[](https://coveralls.io/github/Cherry/network-error-logging?branch=master)
[](https://app.fossa.io/projects/git%2Bgithub.com%2FCherry%2Fnetwork-error-logging?ref=badge_shield)
This is Express middleware to set the `NEL` HTTP response header. You can read more about it [here](https://www.w3.org/TR/network-error-logging/#nel-response-header).
To use:
```javascript
const NEL = require('network-error-logging')
// ...
app.use(NEL({
report_to: 'endpoint-1', // REQUIRED to register. OPTIONAL if intention is to remove a previous registration. defined in the Report-To header
max_age: 31536000, // REQUIRED. seconds
include_subdomains: true, // OPTIONAL
success_fraction: 0.5, // OPTIONAL. sampling rate
failure_fraction: 0.5, // OPTIONAL. sampling rate
request_headers: ["If-None-Match"], // OPTIONAL. request headers whose names and values are included in the network error reports
response_headers: ["ETag"] // OPTIONAL. response headers whose names and values are included in the network error reports
}))
```
For further documentation on each field, see https://w3c.github.io/network-error-logging/#nel-response-header.
This header is best set with a previously defined `Report-To` group. [This module](https://github.com/Cherry/report-to) is a great way to do that.
https://report-uri.com/ is a great reporting platform for monitoring CSP, NEL, etc. error logs.
[](https://app.fossa.io/projects/git%2Bgithub.com%2FCherry%2Fnetwork-error-logging?ref=badge_large)