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

node http2 error #19406

Closed
fengyun2 opened this issue Mar 17, 2018 · 11 comments
Closed

node http2 error #19406

fengyun2 opened this issue Mar 17, 2018 · 11 comments

Comments

@fengyun2
Copy link

fengyun2 commented Mar 17, 2018

  • Version: v9.8.0
  • Platform: windows10(64-bit)
  • Subsystem:
  • Browser: Chrome 62

http2

// server/index.js
// node 版本v9+ http2访问不成功,(启动不报错,但是在浏览器访问不到)
const http2 = require('http2')
const fs = require('fs')
const path = require('path')
const resolve = (dir) => path.join(__dirname, '..' , dir)
const options = {
  key: fs.readFileSync('privatekey.pem'),
  cert: fs.readFileSync('certification.pem')
}

 const http2App = http2.createServer(options, (req, res) => {
  res.writeHead(200)
  res.end('hello http2\n')
})

http2App.listen('8002', '0.0.0.0', () => {
  console.log('HTTP2 Server running at https://0.0.0.0');
})

Running node./server/index.js has no error, but access to the https://localhost:8002 failed.

@richardlau
Copy link
Member

For https you should use createSecureServer instead of createServer.

@styfle
Copy link
Member

styfle commented Mar 19, 2018

@fengyun2 Did that fix your problem?

@Trott Should the docs be updated to indicate that http2.createServer is likely not what the user wants since no browsers (that I'm aware of) support unencrypted HTTP/2 connections?

@Trott
Copy link
Member

Trott commented Mar 19, 2018

@Trott Should the docs be updated to indicate that http2.createServer is likely not what the user wants since no browsers (that I'm aware of) support unencrypted HTTP/2 connections?

I'll defer to @nodejs/http2 and @nodejs/documentation

@mcollina
Copy link
Member

I think we should update the docs, yes.

@trivikr
Copy link
Member

trivikr commented Mar 19, 2018

This quote by @richardlau is correct

For https you should use createSecureServer instead of createServer

The fallback mechanism to use HTTP/1.1 is not available on Http2Server as discussed in #18554
As @Trott mentioned the browsers won't support unencrypted HTTP/2 connections, but Http2Server can be used in certain cases - like communication between microservices if they're on the same host (a rare use case)

@mcollina
Copy link
Member

@trivikr I typically use it all the time in tests. Spinning up tls connections costs time.

@styfle
Copy link
Member

styfle commented Mar 19, 2018

I can submit a PR to update the docs but I'm not sure what to write because it's not like it's a deprecated method, it's just not advised in most cases.

What verbiage should be used to steer users away from createServer and towards createSecureServer?

@apapirovski
Copy link
Member

apapirovski commented Mar 19, 2018

FWIW the initial example at the top is using createSecureServer: https://nodejs.org/dist/latest-v9.x/docs/api/http2.html#http2_server_side_example

The example preface is actually incorrect because it claims to illustrate a "plain-text" HTTP/2 server. That should be changed. An additional note could be added below the example or perhaps in the createServer documentation that says something along the lines of "Due to a lack of support for plain-text HTTP/2 (h2c) by the major browsers and other client-side implementations, it is recommended to use createSecureServer." Or something like that...

@a0viedo
Copy link
Member

a0viedo commented Mar 19, 2018

FWIW the initial example at the top is using createSecureServer: nodejs.org/dist/latest-v9.x/docs/api/http2.html#http2_server_side_example

There's a lot of code samples that uses createServer though. Maybe a warning on the description of the method would help?

@fengyun2
Copy link
Author

@styfle Has been resolved.Thanks.

@styfle
Copy link
Member

styfle commented Mar 20, 2018

Great! I submitted #19476 which should help anyone else running into this problem.

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

No branches or pull requests

10 participants