Merge branch 'toobusy' of git://github.com/dannycoates/picl-idp into toobusy

Conflicts:
	package.json
This commit is contained in:
Zachary Carter 2013-06-06 09:55:58 -07:00
Родитель 451e56f8d7 d4e7cb9dd6
Коммит 90909ccdff
2 изменённых файлов: 27 добавлений и 3 удалений

Просмотреть файл

@ -28,7 +28,8 @@
"kvstore": "git://github.com/mozilla/node-kvstore.git#4b8c2f6763",
"good": "git://github.com/dannycoates/good.git#223e5d6db3",
"heka": "git://github.com/dannycoates/heka-node.git#db91220ec0",
"node-statsd": "0.0.7"
"node-statsd": "0.0.7",
"toobusy": "0.2.3"
},
"devDependencies": {
"awsbox": "0.4.5",

Просмотреть файл

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Hapi = require('hapi');
const toobusy = require('toobusy');
const config = require('./lib/config');
const routes = require('./routes');
@ -23,13 +24,24 @@ var bind = config.get('bind_to');
var server = Hapi.createServer(bind.host, bind.port, settings);
server.addRoutes(routes);
server.ext(
'onRequest',
function (request, next) {
var exit = false;
if (toobusy()) {
exit = Hapi.error.serverTimeout('Server too busy');
}
next(exit);
}
);
server.ext(
'onPreResponse',
function (request, next) {
var res = request.response();
// error responses don't have `header`
if (res.header) {
res.header("Strict-Transport-Security", "max-age=10886400");
res.header('Strict-Transport-Security', 'max-age=10886400');
}
next();
}
@ -68,8 +80,19 @@ server.pack.require('good', {
}
);
process.on(
'SIGINT',
function () {
console.log("shutting down");
server.stop(
function () {
toobusy.shutdown();
}
);
}
);
//TODO throttle extension
//TODO toobusy extension
module.exports = server;