簡體   English   中英

解析node.js中的每個網址節流

[英]throttle per url in node.js restify

文件說明:

請注意,您始終可以將其放在每個URL路由上,以便為不同的資源啟用不同的請求速率(例如,一個路由,比如/ my / slow / database比/ my / fast / memcache更容易overwhlem)。

我無法找到如何完全實現這一點。

基本上,我想以與我的API不同的節流速率提供靜態文件。

設置限制(速率限制器),為這樣的某些端點解析。

    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();
        }
    );

即使在每個端點進行節流時,仍然需要全局節流,因此可以這樣做。

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

(參考) Throttle是restify的插件之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM