title: webpack-dev-server does not properly proxy redirect to the backend with hapi and and hapi-auth-cookie
body: <p>When i boot up the hapi-server as well as the webpack-dev-server and go to localhost:3000/api/login shows a 502 bad gateway and nothing on the page! Thanks for every one who helps</p>
  
  <p>Here is my webpack file:</p>
  
  <pre><code>module.exports = {
      entry: ["./index.js"],
      output: {
          filename: "bundle.js"
      },
      module: {
          loaders: [
              {
                  test: /\.js$/,
                  exclude: /node_modules/,
                  loader: 'babel-loader',
                  query: {
                      presets: ['react', 'es2015']
                  }
              }
          ]
      },
      resolve: {
          extensions: ['', '.js', '.jsx']
      },
      devServer: {
          historyApiFallback: {
              index: 'index.html'
          },
          stats: 'normal',
          host: process.env.HOST || 'localhost',
          port: process.env.PORT || 3000,
          proxy: {
              '/api/*': {
                  target: 'http//localhost:9000',
                  secure: false
              }
          }
      }
  };
  </code></pre>
  
  <p>Here is my hapi-server:</p>
  
  <pre><code>const Hapi = require('hapi');
  const Inert = require('inert');
  const config = require('./config');
  const CookieAuth = require('hapi-auth-cookie');
  
  const server = new Hapi.Server();
  server.connection({port: 9000});
  
  const options = {
      ops: {
          interval: config.hapiGoodInterval
      },
      reporters: {
          console: [{
              module: 'good-squeeze',
              name: 'Squeeze',
              args: [{ log: '*', response: '*' }]
          }, {
              module: 'good-console'
          }, 'stdout'],
          file: [{
              module: 'good-squeeze',
              name: 'Squeeze',
              args: [{ ops: '*' }]
          }, {
              module: 'good-squeeze',
              name: 'SafeJson'
          }, {
              module: 'good-file',
              args: ['./logs/fixtures/file_log']
          }]
      }
  };
  server.register(CookieAuth, (err) =&gt; {
      if (err) {
          throw err;
      }
  });
  
  server.register(Inert, ()=&gt;{});
  server.register({
      register: require('good'),
      options,
  }, (err) =&gt; {
      if (err) {
          return console.error(err);
      }
      server.start(() =&gt; {
          console.info(`Server started at ${ server.info.uri }`);
      });
  });
  
  const cache = server.cache({ segment: 'sessions', expiresIn: 3 * 24 * 60 * 60 * 1000 });
  server.app.cache = cache;
  
  server.auth.strategy('session', 'cookie', true, {
      password: 'Vaj57zED9nsYeMJGP2hnfaxU874t6DV5',
      cookie: 'sid-example',
      redirectTo: '/api/login',
      isSecure: false,
      validateFunc: function (request, session, callback) {
  
          cache.get(session.sid, (err, cached) =&gt; {
  
              if (err) {
                  return callback(err, false);
              }
  
              if (!cached) {
                  return callback(null, false);
              }
  
              return callback(null, true, cached.account);
          });
      }
  });
  
  server.route(require('./routes'));
  </code></pre>
  
  <p>Here are the routes:</p>
  
  <pre><code>var Handlers = require('./handlers');
  var Joi = require('joi');
  var Routes = [
    {
        path: '/api/hello',
        method: 'GET',
        config: {
            auth:false,
            handler: function (request, reply) {
                reply('Hello from the server')
            }
        }
    },
    {
      method: ['GET', 'POST'],
      path: '/api/login',
      config: {
          handler: Handlers.login,
          auth: { mode: 'try' },
          plugins: {
            'hapi-auth-cookie': { redirectTo: false }
          }
      }
    },
    {
      path: '/api/logout',
      method: 'GET',
      handler: Handlers.logout
    }
  ];
  </code></pre>
  
  <p>And Finally the handlers:</p>
  
  <pre><code>const r = require('rethinkdb');
  var {Post, User, Opinion} = require('./rethinkdb/models/all');
  
  class Handlers {
  
      static login(request, reply) {
          let username = 'pesho';
          let password = '12345';
  
          let uuid = 1;
  
          if (request.auth.isAuthenticated) {
              return reply.redirect('/');
          }
  
          let message = '';
          let account = null;
  
          if (request.method === 'post') {
  
              if (!request.payload.username ||
                  !request.payload.password) {
  
                  message = 'Missing username or password';
              }
              else {
                  if (password !== request.payload.password || username !== request.payload.username) {
                      message = 'Invalid username or password';
                  }
              }
          }
  
          if (request.method === 'get' || message) {
  
              return reply('&lt;html&gt;&lt;head&gt;&lt;title&gt;Login page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;' +
                  (message ? '&lt;h3&gt;' + message + '&lt;/h3&gt;&lt;br/&gt;' : '') +
                  '&lt;form method="post" action="/api/login"&gt;' +
                  'Username: &lt;input type="text" name="username"&gt;&lt;br&gt;' +
                  'Password: &lt;input type="password" name="password"&gt;&lt;br/&gt;' +
                  '&lt;input type="submit" value="Login"&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;');
  
          }
  
          const sid = String(++uuid);
          request.server.app.cache.set(sid, { account: account }, 0, (err) =&gt; {
  
              if (err) {
                  reply(err);
              }
  
              request.cookieAuth.set({ sid: sid });
              return reply.redirect('/');
          });
      }
  
      static logout(request, reply) {
          request.cookieAuth.clear();
          return reply.redirect('/');
      };
  }
  
  module.exports = Handlers;
  </code></pre>