title: http-proxy-middleware not proxying requests if placed after cookieparser
body: <blockquote>
    <ol>
    <li>The middleware works properly if placed before the cookie parser.But
    the session becomes undefined.</li>
    <li>If i move the proxy middleware after the cookie parser it does not
    proxy requests silently fails without any errors.I tried creating a post request but nothing happens.</li>
    </ol>
  </blockquote>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var session = require('express-session');
  var cors = require('cors');
  var redis = require('redis');
  var redisClient = redis.createClient();
  var RedisStore = require('connect-redis')(session);
  var proxy = require('http-proxy-middleware');
  var config = require('config');
  
  var index = require('./routes/index');
  var users = require('./routes/users');
  
  var app = express();
  
  var sessionMiddleware = session({
    store: new RedisStore({
      client:redisClient
    }),
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true
  });
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'hbs');
  app.use(sessionMiddleware);
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  //cookie parser
  app.use(cookieParser());
  
  app.use(express.static(path.join(__dirname, 'public')));
  app.use('/bower_components',  express.static(__dirname + '/bower_components'));
  app.use(cors());
  
  //proxy middleware
  app.use('/api', proxy({
      target: 'http://localhost:4000', 
      changeOrigin: true, 
      onProxyReq:  function (proxyReq, req, res) {
        proxyReq.setHeader('USER_ID', req.session.user_id);
        proxyReq.setHeader('TOKEN',config.get('token'));
      }      
  }));
  
  app.use('/', index);
  app.use('/users', users);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  module.exports = app;
  </code></pre>
  
  <blockquote>
    <p>http-proxy-middleware npm module middleware </p>
  </blockquote>
  
  <pre><code>app.use('/api', proxy({
      target: 'http://localhost:4000', 
      changeOrigin: true, 
      onProxyReq:  function (proxyReq, req, res) {
        proxyReq.setHeader('USER_ID', req.session.user_id);
        proxyReq.setHeader('TOKEN',config.get('token'));
      }      
  }));
  </code></pre>