Search code examples
node.jsexpressnewrelicrestify

How To Set Up A Ping Route (HEAD) For New Relic In Restify/Express


I need to monitor my application's uptime via New Relic. I'm using the Restify framework which is largely based on Express.

New Relic wants to make HEAD requests to my application, but I'm not sure how to set up a HEAD route correctly to satisfy New Relic. Currently, my Restify app returns a 405 error for "Method Not Allowed", which causes New Relic to have fits and send me non-stop emails about how my application is down, and I can't find any documentation from New Relic that shows how to set up a simple ping URL to satisfy them.

Is there anything I need to do other than this:

server.head('/ping', function(error, req, res) {
    res.send("hello");
});

Solution

  • EDIT:

    The parameters are mislabeled so the res.send() is actually trying to call next().send() which would be undefined. Removing the error parameter and shifting everything over fixed the code as discovered by the OP.


    As per the restify documentation, you need to call return next() in your callback function:

    http://mcavage.me/node-restify/#Routing

    server.head('/ping', function (req, res) {
        res.send('hello');
    });
    

    If you would like to respond immediately and not continue down the chain, you can pass false as a parameter in your call to next()