node.js中每个url的节stream阀都可以调整

该文件指出:

请注意,您始终可以在每个URLpath上放置此值,以针对不同的资源启用不同的请求率(例如,如果/ my / slow / database比/ my / fast / memcache更容易过度)。

我很难find如何实现这一点。

基本上,我想以不同于API的静态文件来提供静态文件。

设置限制(速率限制器)与restify像这样的一些端点。

var rateLimit = restify.throttle({burst:100,rate:50,ip:true}); server.get('/my/endpoint', rateLimit, function(req, res, next) { // Do something here return next(); } ); server.post('/another/endpoint', rateLimit, function(req, res, next) { // Do something here return next(); } ); 

或者像这样

  server.post('/my/endpoint', restify.throttle({burst:100,rate:50,ip:true}), function(req, res, next) { // Do something here return next(); } ); 

即使在每个端点节stream的情况下,仍然可能需要全局油门,这样就可以这样做。

  server.use(restify.throttle({burst:100,rate:50,ip:true}); 

(引用)Throttle是restify的Bundled-Plugins之一 。