mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
431 B
19 lines
431 B
10 years ago
|
|
||
|
// middleware which blocks requests when the eventloop is too busy
|
||
|
var toobusy = require('toobusy');
|
||
|
|
||
|
function middleware(req, res, next){
|
||
|
if( toobusy() ){
|
||
|
res.status(503); // Service Unavailable
|
||
|
return next('Server Overwhelmed');
|
||
|
}
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
// calling .shutdown allows your process to exit normally
|
||
|
process.on('SIGINT', function() {
|
||
|
toobusy.shutdown();
|
||
|
process.exit();
|
||
|
});
|
||
|
|
||
|
module.exports = middleware;
|