webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

Question: What is the status of HTTP/2 support?

Open Aghassi opened this issue 5 years ago • 34 comments

  • Operating System: macOS 10.14.3
  • Node Version: 10
  • Yarn Version: 1.13.0
  • webpack Version: 4.29.4
  • webpack-dev-server Version: 3.2.1
  • [ ] This is a bug
  • [ ] This is a modification request
  • [x] This is a question

I spent about an hour digging around yesterday and couldn't find the answer to this question, so I wanted to post here and get some insight.

I read through https://github.com/webpack/webpack-dev-server/issues/516, which seems to indicate there is HTTP/2 supported, but I couldn't find any docs on how to enable it. All I found in the official docs was the line under this section https://webpack.js.org/configuration/dev-server/#devserverhttps saying that it can run with HTTP/2.

In the code in this repo I found this https://github.com/webpack/webpack-dev-server/blob/21687c3bfc95752957d16470b97d281001dc6a07/lib/Server.js#L633-L660

All of which links to issues and other repos which have either been closed or have no work being done on them. And according to this comment https://github.com/webpack/webpack-dev-server/issues/1493#issuecomment-419493497, it is planned for v4, but nothing in the 4.0.0 milestone https://github.com/webpack/webpack-dev-server/milestone/4 seems to support that statement.

Ultimately, I'm confused as to the current situation. Does Webpack-Dev-Server support HTTP/2? If not, will it be supported in the future?

Aghassi avatar Mar 09 '19 15:03 Aghassi

We support http2 using spdy module for backward compatibility with old node version, to enable http2 you should enable https option and spdy option, but i agree it is misleading, and looks we doesn't respect spdy (https://github.com/webpack/webpack-dev-server/blob/master/bin/options.js), thanks for issue. We need:

  1. Respect spdy (add alias http2) in CLI
  2. Add tests

For future version use http2 module instead node-spdy

alexander-akait avatar Mar 11 '19 09:03 alexander-akait

As an added note, will respecting the spdy option in the CLI also reflect if I am using this programmatically by importing webpack-dev-server?

Aghassi avatar Mar 11 '19 18:03 Aghassi

@Aghassi no, but fix it very easy

alexander-akait avatar Mar 12 '19 09:03 alexander-akait

@evilebottnawi I'm a bit confused: the options file you linked contains no mention of spdy or http2 (or http/2). I've played around with this all evening, and I cannot get webpack-dev-server to serve over http2. Setting a CLI option does nothing, and the same is true for devServer.https.spdy: true (devServer.spdy causes a validation error).

I see it looks like it's coming in #1721, but it sounds like it was there before?

JakobJingleheimer avatar Mar 28 '19 22:03 JakobJingleheimer

@jshado1 yep, now it is broken, this PR solve problem, next week release

alexander-akait avatar Mar 28 '19 22:03 alexander-akait

Fixed https://github.com/webpack/webpack-dev-server/issues/1713, http2 doesn't support on node >= 10 due express doesn't support this right now, we fix it after express was released

alexander-akait avatar Apr 04 '19 16:04 alexander-akait

Mark as feature, we implement support after express do this

alexander-akait avatar Apr 09 '19 18:04 alexander-akait

Any updates on this?

hullevive avatar Jul 25 '19 22:07 hullevive

@hullevive we use express under webpack-dev-server, so if you want http2 support please write this in express issue, we can't do something on our side

alexander-akait avatar Jul 26 '19 10:07 alexander-akait

Still an issue in 2020? Trying to setup a localhost with https. I'm getting : HTTP/2 is currently unsupported for Node 10.0.0 and above, but will be supported once Express supports it Is there a release that has some sort of workaround? Even if it's dirty, I just need HTTPS for my vue app that uses webpack, thanks!

ereztdev avatar Mar 24 '20 10:03 ereztdev

@ereztdev please write about it in express repo, they still not implement http2 support in 2020

alexander-akait avatar Mar 24 '20 10:03 alexander-akait

expressjs/express#2761

JakobJingleheimer avatar May 04 '20 04:05 JakobJingleheimer

@evilebottnawi Is there a workaround in the meantime with node > 10.0 ? Using http/1.1 is so slow for development...

Edit: Here is example of a caddyfile to run a caddy reverse proxy for http/2:

localhost:3001

reverse_proxy 127.0.0.1:3000
tls localhost.pem localhost-key.pem

devServer should be run on port 3000 in this case. And caddy reverse proxy listens on port 3001. If you need to generate local certificates, I recommend mkcert

Herz3h avatar Jun 25 '20 09:06 Herz3h

@Herz3h you can launch nginx or caddy and setup proxy to webpack-dev-server

7rulnik avatar Jun 25 '20 11:06 7rulnik

spdy is effectively unmaintained

It just got an update this year after a long break, perhaps we should reconsider using it when developers explicitly want to? I'm using spdy for my personal project (it serves HTTP/2 well - unlike http2) and so far have no major issues with it on newest Node (14.x).

wojtekmaj avatar Aug 03 '20 13:08 wojtekmaj

We should revive this

isrmicha avatar Sep 11 '20 00:09 isrmicha

The issues preventing spdy from working on node > 11.1 are now fixed, btw: https://github.com/spdy-http2/handle-thing/pull/13

dflock avatar Oct 23 '20 21:10 dflock

Node 15.0.1 have HTTP/3 QUIC experimental support. webpack-dev-server will implement that ?

isrmicha avatar Oct 24 '20 15:10 isrmicha

How feasible would it be to use a different framework than Express to power webpack-dev-server? Express 5.0, which is tilted to have full http2 support, has been in alpha for about 7 years now, and there is no clear roadmap indicating when it will be released. Competing frameworks (koa, fastify etc) have all supported it for years and are actively maintained.

I asked the developers about the maintenance status and roadmap, and it seems to mostly boil down to them not having the resources and hoping the community will pitch in: https://github.com/expressjs/express/issues/4451

csvan avatar Nov 01 '20 17:11 csvan

we are looking at fastify for the our next default development framework

alexander-akait avatar Nov 02 '20 11:11 alexander-akait

Express have thrown in the towel on http2: They've essentially said they're married to an underlying dead lib, spdy, for http2 support, so Express is unfortunately dying a slow death.

JakobJingleheimer avatar Nov 05 '20 03:11 JakobJingleheimer

Guys, this is awkward, but... I just checked and http2 flag.... Works? Looks like the specific check that prevented it from being enabled on Node 10+ is gone from lib/Server.js with this change:

https://github.com/webpack/webpack-dev-server/commit/b0161e9852cdf41730e82aa43efe7e88f44a4f9d#diff-b706bbadb3d2315d99678f05e1f4bfd78a4bb4a7a6c65f3e81f1386fee3c883aL669-L678

So webpack-dev-server 4.0.0-beta.0 and up should run http/2 just fine. And it does!

image

wojtekmaj avatar Aug 18 '21 12:08 wojtekmaj

Yep, should work

alexander-akait avatar Aug 18 '21 12:08 alexander-akait

Stable release will be today

alexander-akait avatar Aug 18 '21 12:08 alexander-akait

Can confirm that https: true works great in 4.0. Awesome work @alexander-akait

csvan avatar Aug 19 '21 07:08 csvan

Can we close this issue then?

snitin315 avatar Aug 19 '21 07:08 snitin315

...however, http2 is quite unstable. Pretty sure that has to do with the SPDY package though.

csvan avatar Aug 19 '21 16:08 csvan

Yep, if we need http2, we need fix compatibility with http2 module in express or migrate on fastify or other frameworks, it requires more work, firstly we should do compatibility inside webpack-dev-middleware, but there are more middleware which require compatibility too

alexander-akait avatar Aug 19 '21 16:08 alexander-akait

Seems like http2 is being supported now, but I observed that the proxy downgrades requests from http2 to http1.1, which was weird 🤔 Is that a known issue?

computnik avatar Apr 29 '22 06:04 computnik

@computnik Can you clarify?

alexander-akait avatar Apr 29 '22 15:04 alexander-akait