Since upgrading to Express 4.0 (from 3.0), all my DELETE REST calls are not authenticating because i notice that the body params (where the access_token use to be stored in) are not available for DELETE calls.
Whenever i use GET/PUT/etc., those params are being passed flawlessly.
If anyone have any idea why it doesn't work for DELETE calls, please let me know.
Thx, Ori
Updated:
so I figured out that because i'm using postman, the delete is submitted as multipart, hence, i need to add a special "add on", so I added multer (app.use(multer());), however, it still doesn't work, here is my code:
var express = require('express'),
morgan = require('morgan'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
//session = require('express-session'),
multer = require('multer'),
mongoose = require('mongoose'),
passport = require('passport'),
// Create Application
app = express();
// configurate the app
app.use(require('stylus').middleware(path.join(__dirname, 'web')));
app.use(express.static(__dirname + '/web'));
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(multer());
app.use(methodOverride());
and my delete function looks like:
app.delete('/api/company/:id/email',auth.clientAuth(), auth.bearerAuth({scope:[1]}), company.deleteEmail);
Where the "auth.clientAuth()" and the "auth.bearerAuth({scope:[1]})" handle authorization and entitlement.
At the same time, how can I have this "chain" of both the auth and the entitlements in the new chaining of express 4.0?
Since you're not showing your code, I believe you are not passing param as object. here is a delete example which works well with express 4
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
var router = express.Router();
router.route('/users/:user_id')
.delete(function(req,res){
User.remove({_id: req.params.user_id},function(err, user){
if(err) res.json({message: err})
res.json({message: 'User removed from DB!'});
});
});