Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listening as both https and http server simultaneously #126

Open
kwindla opened this issue Mar 9, 2015 · 30 comments
Open

listening as both https and http server simultaneously #126

kwindla opened this issue Mar 9, 2015 · 30 comments

Comments

@kwindla
Copy link

kwindla commented Mar 9, 2015

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.

@sokra
Copy link
Member

sokra commented Mar 25, 2015

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.

@sokra sokra closed this as completed Mar 25, 2015
@tommedema
Copy link

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

@mzedeler
Copy link

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(...).

@Jokero
Copy link

Jokero commented Aug 16, 2017

This is actually not so rare situation 👍 I need also both http and https

@Jokero
Copy link

Jokero commented Aug 19, 2017

Redirect from http to https also would be ok

@kitsunekyo
Copy link

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

@Jokero
Copy link

Jokero commented Jul 31, 2018

@sokra Looks like this is not rare situation 😃

@jasonjiflyer
Copy link

This is really not rare situation

@ehausen
Copy link

ehausen commented Aug 30, 2018

I would also need both!

@michaelhartmayer
Copy link

Yes please.

@jayarjo
Copy link

jayarjo commented Aug 24, 2019

We need this!

@everscending
Copy link

I need this as well. Bump!

@anandchakru
Copy link

another +1 for this..

@kmukthi
Copy link

kmukthi commented Nov 21, 2019

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.

@alexander-akait
Copy link
Member

For me - we need option to:

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

@rightaway
Copy link

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.

@natkuhn
Copy link

natkuhn commented Jan 25, 2021

+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."

@extempl
Copy link

extempl commented Mar 12, 2021

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

@taylorgoolsby
Copy link

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.

@kamilic
Copy link

kamilic commented Nov 3, 2021

Bump priority. We NEED this feature.

@sandorvasas
Copy link

still need it

@ruojianll
Copy link

I need it.

@alexander-akait
Copy link
Member

alexander-akait commented Apr 18, 2022

PR welcome, we can start 2 servers

@flavianh
Copy link

flavianh commented Jun 2, 2022

Need this too

@pedrettin
Copy link

I consider this a hack, so i still think a proper webpack property to allow redirect is needed, but here is a solution only using webpack and without having to spin up another local server frontend by nginx.

Basic idea: spin up 2 webpack dev servers, 1 listening on http one on https. Have the one listening on http implement a proxy to redirect to https.

// package.json

"server": "webpack serve --config webpack.config.js --env https=false & webpack serve --config webpack.config.js --env https=true",

// webpack.config.js

module.exports = (env) => {
	return {
		....
		devServer: {
			https: env && env.https === "true",
			...
			port: env && env.https === "true" ? 443 : 80,
			...
			proxy: !env || env.https === "false" ? {
				"/**": {
					target: "https://localhost",
					secure: false, // allows the https server to not have a proper certificate
				}
			} : {}
		},
		...
	};

}

@alexander-akait
Copy link
Member

Why you need HTTPS on dev env? Due http2/http3 support?

@pedrettin
Copy link

I am guessing there are multiple use cases, but we need it to communicated with the auth service which does not do CORS with non https services.

@alexander-akait
Copy link
Member

Why not use HTTPs and self signed certificate?

@pedrettin
Copy link

that's what we do

@hieuzeta
Copy link

I also need to serve both http and https, any progress on this thread ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests