200-ok-boomer 中文文档教程

发布于 4年前 浏览 28 项目主页 更新于 3年前

npm Codecov

200-ok-boomer

将“200 OK”转换为“200 OK Boomer”的中间件

这个项目不应该被认真对待或以任何方式作为政治声明。 它提供一个带有Express Middleware签名的单一函数okBoomer function okBoomer(req, res, next)

这个中间件覆盖了请求的send 方法来传输“OK Boomer”的statusMessage 只要 statusCode 是 200。就是这样,就是这样。

为了正常工作,这个中间件应该在请求处理程序或任何其他可以 将标头传输给客户端,因为它在作为中间件调用时替换了 Response 对象上的方法。

Usage

对于 Express 应用程序,只需要求 200-ok-boomer 并作为中间件应用 例如

const express = require('express');
const okBoomer = require('200-ok-boomer');

const app = express();
app.use(okBoomer());
app.get('/', (req, res) => res.sendStatus(200));
server = app.listen(5000);
$curl -I localhost:5000
HTTP/1.1 200 OK Boomer

Telemetry

,从 2.0.0 版开始,200-ok-boomer 默认会发出简单的指标(200 OK Boomer 响应的计数)。 这将通过定期(每分钟一次)调用具有聚合计数的指标端点来完成。

如果这种行为是不可取的,请传递一个指定“collectMetrics”为 false 的配置对象:

app.use(okBoomer()); // Will collect and transmit metrics
app.use(okBoomer({collectMetrics: false})); // Will NOT collect and transmit metrics

npm Codecov

200-ok-boomer

Middleware to convert "200 OK" into "200 OK Boomer"

This project shouldn't be taken seriously or in any way as a political statement. It only provides a single function okBoomer which has the signature of Express Middleware function okBoomer(req, res, next)

This middleware overwrites the send method of the request to transmit a statusMessage of "OK Boomer" along as long as statusCode is 200. That's it, that's all it does.

In order to work properly this middleware should be registered before request handlers or anything else which can transmit headers to clients since it replaces methods on the Response object at the time it is invoked as middleware.

Usage

In the case of an Express app, simply require 200-ok-boomer and apply as middleware e.g.

const express = require('express');
const okBoomer = require('200-ok-boomer');

const app = express();
app.use(okBoomer());
app.get('/', (req, res) => res.sendStatus(200));
server = app.listen(5000);
$curl -I localhost:5000
HTTP/1.1 200 OK Boomer

Telemetry

As of version 2.0.0, 200-ok-boomer will by default emit simple metrics (a count of 200 OK Boomer responses). This will be done by periodically (once per minute) calling a metrics endpoint with an aggregated count.

If this behavior is undesirable, please pass a configuration object specifying "collectMetrics" to be false:

app.use(okBoomer()); // Will collect and transmit metrics
app.use(okBoomer({collectMetrics: false})); // Will NOT collect and transmit metrics
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文