Skip to content
Snippets Groups Projects
Commit 521e2aad authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

don't log calls to __heartbeat__ closes #537

parent 65d1f57a
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,8 @@ if (!config.get('keysigner_url')) {
process.exit(1);
}
// NOTE: ordering is important in this file. Pay attention
function router(app) {
app.set("views", path.join(__dirname, "..", "resources", "views"));
......@@ -171,12 +173,6 @@ function router(app) {
// register all the WSAPI handlers
wsapi.setup(app);
// setup health check / heartbeat
heartbeat.setup(app, function(cb) {
// let's check stuff! first the heartbeat of our keysigner
heartbeat.check(config.get('keysigner_url'), cb);
});
// the public key
app.get("/pk", function(req, res) {
res.json(config.get('public_key').toSimpleObject());
......@@ -203,6 +199,13 @@ function router(app) {
});
};
// #1 - Setup health check / heartbeat middleware.
// This is in front of logging on purpose. see issue #537
heartbeat.setup(app, function(cb) {
// let's check stuff! first the heartbeat of our keysigner
heartbeat.check(config.get('keysigner_url'), cb);
});
// request to logger, dev formatted which omits personal data in the requests
app.use(express.logger({
format: config.get('express_log_format'),
......
const urlparse = require('urlparse');
const
urlparse = require('urlparse'),
logger = require('./logging.js').logger;
// the path that heartbeats live at
exports.path = '/__heartbeat__';
// a helper function to set up a heartbeat check
exports.setup = function(app, cb) {
app.get(exports.path, function(req, res) {
function ok(yeah) {
res.writeHead(yeah ? 200 : 500);
res.write(yeah ? 'ok' : 'not ok');
res.end();
app.use(function(req, res, next) {
if (req.method === 'GET' && req.path === exports.path) {
function ok(yeah) {
res.writeHead(yeah ? 200 : 500);
res.write(yeah ? 'ok' : 'not ok');
res.end();
}
try {
if (cb) cb(ok);
else ok(true);
} catch(e) {
logger.error("Exception caught in heartbeat handler: " + e.toString());
ok(false);
}
} else {
return next();
}
if (cb) cb(ok);
else ok(true);
});
};
......@@ -35,4 +46,4 @@ exports.check = function(url, cb) {
logger.error("can't communicate with " + shortname + ". fatal: " + e);
cb(false);
});
};
\ No newline at end of file
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment