Webpack-dev-server: Unable to redirect HTTP requests to HTTPS

Created on 31 Mar 2019  路  4Comments  路  Source: webpack/webpack-dev-server

  • Operating System: Linux
  • Node Version: 11.7.0
  • NPM Version: 6.8.0
  • webpack Version: 4.29.6
  • webpack-dev-server Version: 3.2.1

  • [x] This is a bug
  • [ ] This is a modification request

Code

// webpack.config.js
devServer: {
    compress: true,
    contentBase: path.join(__dirname, 'dist'),
    disableHostCheck: true,
    host: '0.0.0.0',
    hot: true,
    https: Boolean(env && env.SERVER === 'production') && {
      ca: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/fullchain.pem'),
      cert: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/cert.pem'),
      key: fs.readFileSync('/etc/letsencrypt/live/mydomain.com/privkey.pem')
    },
    port: 3000
  }

Expected Behavior

When accessing my site via https://mydomain.com, it should work (and it does).
When accessing my site via mydomain.com (HTTP), it should route to the HTTPS version.

Actual Behavior

There is no rerouting

All 4 comments

Not sure it is good for DX purpose, why you need this?

Also it is development server, so it is good DX to allow developers use http and https together, so i am closing this issue, maybe be we will revisit it in future, feel free to feedback, thanks

@jakeleventhal Any chance you got this working? I have a Vue app configured this way and it only works with "https://" specified. It would be nice if http can be redirected to https.

@zachzeyuwang
I wasn't able to do this. Instead I used nginx to reroute requests

Was this page helpful?
0 / 5 - 0 ratings