{"library":"report-to","title":"Express Report-To Middleware","description":"This package provides Express.js middleware for setting the HTTP `Report-To` response header, crucial for client-side error reporting via browser APIs. Currently at version 1.1.0, it appears to be in a maintenance phase with no major updates since 2021. Its primary function is to configure reporting endpoints for various browser features, such as `Content-Security-Policy` (CSP) violation reports, Network Error Logging (NEL), or Intervention Reports. A key differentiator is its focus solely on configuring the `Report-To` header, rather than implementing the reporting mechanisms themselves. This design choice means it requires integration with other modules (e.g., `network-error-logging` for NEL) to make the reporting functional. The module offers a structured way to define report groups, `max_age`, `include_subdomains`, and multiple prioritized endpoints, adhering to the W3C Reporting API specification.","language":"javascript","status":"maintenance","last_verified":"Thu Apr 23","install":{"commands":["npm install report-to"],"cli":null},"imports":["import reportTo from 'report-to';","const reportTo = require('report-to');","import type { ReportToOptions } from 'report-to';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import express from 'express';\nimport reportTo from 'report-to';\n\nconst app = express();\n\napp.use(reportTo({\n    groups: [\n\t\t{\n\t\t\tgroup: \"endpoint-1\",\n\t\t\tmax_age: 10886400,\n\t\t\tinclude_subdomains: true,\n\t\t\tendpoints: [\n\t\t\t\t{\n\t\t\t\t\turl: \"https://example.com/reports\",\n\t\t\t\t\tpriority: 1\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\turl: \"https://backup.com/reports\",\n\t\t\t\t\tpriority: 2\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}));\n\n// Example of also setting NEL header, which uses the 'endpoint-1' group defined above\napp.use((req, res, next) => {\n  res.setHeader('NEL', '{\"report_to\":\"endpoint-1\",\"max_age\":31536000,\"include_subdomains\":true}');\n  next();\n});\n\napp.get('/', (req, res) => {\n  res.send('Hello with Report-To and NEL headers!');\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on port ${PORT}`);\n});","lang":"typescript","description":"This quickstart demonstrates how to integrate `report-to` middleware into an Express application, defining a reporting group. It also includes an example of how a complementary `NEL` header would be set, referencing the defined reporting endpoint, as the `Report-To` header alone does not trigger reports.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}