node.js - How do I check Content-Type using ExpressJS? -


i have pretty basic restful api far, , express app configured so:

app.configure(function () {   app.use(express.static(__dirname + '/public'));   app.use(express.logger('dev'));   app.use(express.bodyparser()); });  app.post('/api/vehicles', vehicles.addvehicle); 

how/where can add middleware stops request reaching app.post , app.get if content type not application/json?

the middleware should stop request improper content-type url begins /api/.

this mounts middleware @ /api/ (as prefix) , checks content type:

app.use('/api/', function(req, res, next) {   var contype = req.headers['content-type'];   if (!contype || contype.indexof('application/json') !== 0)     return res.send(400);   next(); }); 

Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -