Webpack-dev-server: listening as both https and http server simultaneously

Created on 9 Mar 2015  路  19Comments  路  Source: webpack/webpack-dev-server

Hi,

I'm moving a project over from browserify to webpack and hit a snag this afternoon. For arcane reasons (involving chrome and atom-shell/chromium behaviors) I need both https and http instances of local dev/testing web servers.

webpack-dev-server is awesome, but I didn't find any directly supported way to instantiate on two ports at the same time.

Here's what I ended up doing (full code context, farther down below)...

webpack_dev_server.listen(8004);
http.createServer(webpack_dev_server.app).listen (8005);

I'd like to ask whether this is a reasonable solution, or whether there's a better thing I should be doing, or alternatively whether a pull request to implement simultaneous https/http at the API level would be welcome.

Below, the full gulpfile.js chunk ...

var webpack = require ("webpack");
var WebpackDevServer = require ("webpack-dev-server");
var webpackConfig = require ("./webpack.config.js");
var http = require ('http');

gulp.task ("webpack-dev-server", function (callback) {
    // modify some webpack config options
    var myConfig = Object.create (webpackConfig);
    myConfig.devtool = "#source-map";
    myConfig.debug = true;

    // Start a webpack-dev-server
    var wds = new WebpackDevServer (webpack(myConfig), {
    https: true,
        publicPath: "/web",    // +   myConfig.output.publicPath,
        stats: {
            colors: true
        }
    });
  wds.listen(8004);
  http.createServer(wds.app).listen (8005);
});

Thank you.

help wanted 4 (nice to have) server minor feature

Most helpful comment

Redirect from http to https also would be ok

All 19 comments

Glad you found a solution, but I think the use case is too rar to add options for this to the webpack-dev-server. Even without accessing internals you could start a proxy server.

I would like to see this actually. For the command line especially.

Does this also work with websockets?
I'm constantly getting http 404 for http://localhost:3001/sockjs-node/info?t=<...> when i use http.createServer(wds.app).listen(...).

This is actually not so rare situation :+1: I need also both http and https

Redirect from http to https also would be ok

bump. i always need both environments.
is this possible yet?

@sokra Looks like this is not rare situation :smiley:

This is really not rare situation

I would also need both!

Yes please.

We need this!

I need this as well. Bump!

another +1 for this..

So a trick would be to configure nginx and open the port 80 to reroute to the actual ssecure locatio. Something like the following in your nginx configuration
server { listen 80; return 301 https://www.example.com$request_uri; }

This works for me, but I would like to know If i can remove the dependency on nginx and only configure web pack.
Thanks.

For me - we need option to:

  • run both server
  • allow to redirect traffic from one to two (http -> https)

Having the option to redirect http to https would be quite helpful. Now I have to always add the https to the beginning of my development links in the browser.

+1. I am using this to test development of an app to communicate with people who are not technically sophisticated. Easier to get them to type "devsite.com" into address bar than "https://devsite.com."

Bump priority. it was a surprise to me that such a functionality is not out-of-the-box.

Now that Chrome is blocking third party cookies unless they are secure, I think this feature is more important for developer experience since it will become more common for devs to have a need for https during dev.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uMaxmaxmaximus picture uMaxmaxmaximus  路  3Comments

wojtekmaj picture wojtekmaj  路  3Comments

piotrszaredko picture piotrszaredko  路  3Comments

nikirossi picture nikirossi  路  3Comments

Jack-Works picture Jack-Works  路  3Comments