node.js server and HTTP/2 (2.0) with express.js

后端 未结 3 699
误落风尘
误落风尘 2020-12-23 13:49

Is it possible currently to get node.js HTTP/2 (HTTP 2.0) server? And http 2.0 version of express.js?

3条回答
  •  粉色の甜心
    2020-12-23 14:04

    var express = require('express');
    var app = express();
    
    app.get('/', function (req, res) {
      res.send('hello, http2!');
    });
    
    var options = {
      key: fs.readFileSync('./example/localhost.key'),
      cert: fs.readFileSync('./example/localhost.crt')
    };
    
    require('http2').createServer(options, app).listen(8080);
    

    EDIT

    This code snippet was taken from a conversation on Github.

提交回复
热议问题