0

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");
});
ac360
  • 7,735
  • 13
  • 52
  • 91

1 Answers1

1

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()

Community
  • 1
  • 1
srquinn
  • 10,134
  • 2
  • 48
  • 54
  • Hi jibsales, It was the `error` parameter in the route handler function that was incorrect. Once I took that out, my route worked fine. You should take it out of your answer. Also, calling `return next()` isn't unnecessary. – ac360 Dec 09 '14 at 21:20
  • @ac360 — Didn't notice that but yes, mislabeling the parameter would have been a problem. I simply copy/pasted which is never a good thing to do! As for returning `next()`, its best practice to _always_ return `next()` simply because you never know when you might mix and match your routes and it makes your code future safe. Necessary? No. Good practice? Absolutely. – srquinn Dec 10 '14 at 01:08