2

I am new to node.js and trying to use express-routes-versioning module in my app.js file and having problem in route version handling.Please help me with my code.

Below is my code please have a look..

` var versionRoutes = require('express-routes-versioning')();

      app.use(bodyParser.json());

    app.use(function(req, res, next) {
   req.version = req.headers['accept-version'];
   next();
});

app.use('/api', versionRoutes({
   "1.0.0": respondV1,
   "2.2.1": respondV2
}));

function respondV1(req, res, next)
 {   
   app.use('/api',route1);
   next();
 }

 function respondV2(req, res, next)
  {
    app.use('/api',routeV2);
    next();
 }

app.use(function(err,req,res,next)
{
   res.status(422).send({"error":err.message});
});`

0 Answers0