Webpack-dev-server: Accessing localhost via devserver stopped working: ERR_UNSAFE_REDIRECT

Created on 13 Aug 2019  ·  14Comments  ·  Source: webpack/webpack-dev-server

  • Operating System:
    Windows 10 64bit
  • Node Version:
    v12.1.0
  • NPM Version:
    6.9.0
  • webpack Version:
    4.39.1
  • webpack-dev-server Version:
    3.8.0
  • Browser:
    Chrome Version 76.0.3809.100 (Official Build) (64-bit)

  • [x] This is a bug

  • [ ] This is a modification request

Code


module.exports = (env, argv) => {

  const config = {

    devServer: {
      allowedHosts: ['localhost', 'local.sli.do', 'admin.local.sli.do'],
      historyApiFallback: true,
      hot: true,
      https: true,
      port: 443,
      public: 'localhost:443'
    },
  };

  return config;
}

Expected Behavior

When I use URL https://localhost/#/something it serves redirects me to https://localhost/something and it works fine. When I want to open https://localhost/something directly, it should serve the content.

Actual Behavior

When I go directly to https://localhost/something I see an error ERR_UNSAFE_REDIRECT and no content is served.

How can we reproduce the behavior?

Just run: node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --colors --mode=development --config=webpack.config.dev.js

server patch 3 (broken) bug

Most helpful comment

host: process.env.HOST || '0.0.0.0'

All 14 comments

Version 3.7.2 works without any problem with the same configuration.

Try to disable historyApiFallback

@evilebottnawi nothing changed as far as I can tell.

EDIT: With historyApiFallback a had two notifications like this:

「wds」: Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.
‼ 「wds」: proxy: {
        "*": "<your current contentBase configuration>"
}

now I have only one, if it helps.

It is full webpack-dev-server configuration?

@evilebottnawi no, but I was able to simulate it with this minimal config as well, so I have pasted only this configuration.

@kmaraz please provide full configuration for webpack-dev-server you have deprecated message, but i can't see any option related to this

@evilebottnawi I is not much different.

const path = require('path');

module.exports = (env, argv) => {

  const context = path.resolve(__dirname, './app');

   const config = {
    context: context,

    entry: {
      app: path.resolve(context, './index'),
    },

    resolve: {
      alias: {},
      modules: ['app', 'node_modules'],
      extensions: ['.js']
    },

    devServer: {
      allowedHosts: ['localhost', 'local.sli.do', 'admin.local.sli.do'],
      historyApiFallback: true,
      hot: true,
      https: true,
      port: 443,
      public: 'localhost:443'
    },

    devtool: 'nosources-source-map',
    target: 'web'
  };

  return config;
}
SET NODE_ENV=development
node --max_old_space_size=10092 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --progress --colors --mode=development --config=webpack.config.dev.js

image

Thanks

Hit possibly same problem, downgrading to 3.7.2 made my code works without any changes, problem appeared after upgrade 3.1.10 -> 3.8.0

Pr welcome if you want so solve this asap

@evilebottnawi not urgent - i was trying to see if problem with websocket connection reset that was causing to proxy stop working is fixed in new version(it wasnt). Im now working with downgraded version of dev server.

host: process.env.HOST || '0.0.0.0'

~I specifically only get this issue when I attempt to access my app through Chrome's "remote devices" tab with ports forwarded. Weirdly, accessing it on a remote device also suddenly makes the host computer stop working too (whereas without a remote device, the host works fine).~

~Can confirm that webpack-dev-server v3.7.2 works fine.~

Edit: tried reinstalling everything and it seems to work now 🤷‍♂

Fixed in master

Was this page helpful?
0 / 5 - 0 ratings