diff --git a/bin/browserid b/bin/browserid
index 3b9a077842a667185c358f5a9f7fa69aa2489983..92c84f0791597edfa137977d417376d876163afe 100755
--- a/bin/browserid
+++ b/bin/browserid
@@ -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'),
diff --git a/lib/heartbeat.js b/lib/heartbeat.js
index faa697c013c543b9a61338f76a589feb2d9b4902..109d8cd560a54222f3c226bd3e7973c54b4987d8 100644
--- a/lib/heartbeat.js
+++ b/lib/heartbeat.js
@@ -1,18 +1,29 @@
-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
+};