mcavage/node-restify — Issue #64: Pre Routing Chain
Author: warorface
Created: 2012-01-31 21:43:42+00:00
State: open

I have been using restify since 0.5.x and while using it I made a few mistakes, like setting non valid semver api version and because of that, now with rangeVersioning it would be nice to have a way to fix those requests before they are routed.

Like this:

var checkAPIVersion = function(req, res, next) {
if (req.headers['x-api-version'] == "*")
res.send (new restify.InvalidVersionError());

if (req.path == "/test2.php" && !req.headers['x-api-version'])
req.headers['x-api-version'] = "1.1.0";

if(req.headers['x-api-version'] == "1.1")
req.headers['x-api-version'] = "1.1.0";

return next();
};

And then run the routing.