镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

node http2 error #19406

Description

@fengyun2
  • 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.

Activity

  1. richardlau commented on Mar 17, 2018

    @richardlau
    Member

    For https you should use createSecureServer instead of createServer.

  2. styfle commented on Mar 19, 2018

    @styfle
    SponsorMember

    @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?

  3. Trott commented on Mar 19, 2018

    @Trott
    Member

    @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

  4. mcollina commented on Mar 19, 2018

    @mcollina
    SponsorMember

    I think we should update the docs, yes.

  5. trivikr commented on Mar 19, 2018

    @trivikr
    Member

    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)

  6. mcollina commented on Mar 19, 2018

    @mcollina
    SponsorMember

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

  7. styfle commented on Mar 19, 2018

    @styfle
    SponsorMember

    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?

  8. apapirovski commented on Mar 19, 2018

    @apapirovski
    Contributor

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

  9. a0viedo commented on Mar 19, 2018

    @a0viedo
    Member

    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?

  10. fengyun2 commented on Mar 20, 2018

    @fengyun2
    Author

    @styfle Has been resolved.Thanks.

  11. styfle commented on Mar 20, 2018

    @styfle
    SponsorMember

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions