Restify用法

  1. RequestLogger
    Sets up a child bunyan logger with the current request id filled in, along with any other parameters you define.
restify.requestLogger({ properties: { foo: 'bar' },
 serializers: {...}
}));```
2. **Throttle(设置阈值)**

server.use(restify.throttle({
burst: 100,
rate: 50,
ip: true,
overrides: {
'192.168.1.1': {
rate: 0, // unlimited
burst: 0
}
}
}));

如果客户端请求超过了限制,服务器会返回429错误
 [Too Many Requests](http://tools.ietf.org/html/draft-nottingham-http-new-status-03#section-4)


| **Name**        | **Type**| **Description**|
| ------------- |:-------------:| -----:|
|rate|Number|每秒请求次数|
|burst|Number|If available, the amount of requests to burst to|
|ip|Boolean|Do throttling on a /32 (source IP)|
|xff|Boolean|Do throttling on a /32 (X-Forwarded-For)|
|username|Boolean|Do throttling on req.username|
|overrides|Object|Per "key" overrides|
|tokensTable|Object|Storage engine; must support put/get|
|maxKeys|Number|If using the built-in storage table, the maximum distinct throttling keys to allow at a time|

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,388评论 19 139
  • 感谢提供照片小伙伴,芳芳芳,阳仔,老冯和鱼桀
    oli_yang阅读 2,629评论 0 0
  • 其实这两天不淡定,一是终于收到心仪公司的Offer,爸妈为之而欣慰。二是有些情绪化,很想发脾气。 总的来说开心还是...
    见夏知晓阅读 4,631评论 0 1
  • 文/张又可 节选自张又可散文集《青春的遗嘱》 我和她在台上翩翩起舞,她小碎花裙,红扑扑的腮红,俩小辫子,时而掩面哭...
    张又可阅读 2,444评论 0 0
  • 瓶颈的喻意一般是指在处理问题时遇到了困难,或某种状态遇到了阻碍,通过攻关可以解决。 比如工作瓶颈。很多...
    鹿鸣阁主阅读 3,764评论 3 1