TypeError:dest.end不是函数

时间:2016-08-25 16:49:52

标签: node.js express http2

我正在尝试使用HTTP / 2。我的快递版本为5.0.0-alpha.2, http2 版本为3.3.4。

我认为 http2 work well with express 5

"p": '"' + p[i] + '"',

服务器开始运行良好,但是当我打开客户端网站时,它在终端中给我这个错误:

const http2 = require('http2');
// const http2 = require('spdy');  // using spdy package here, everything works perfect

const options = {
  key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
  cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};

const server = http2
  .createServer(options, app)
  .listen(3000, err => {
    if (err) throw new Error(err);

    // I can see "Listening..." message, which means the server starts running well.
    console.log('Listening...');
  });

2 个答案:

答案 0 :(得分:2)

Express似乎尚未支持node-http2。 请在github上跟踪此问题Support for module http

同时,您可以使用node-spdy

const spdy = require('spdy');

const options = {
  key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
  cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};

const server = spdy
  .createServer(options, app)
  .listen(3000, err => {
    if (err) throw new Error(err);
    console.log('Listening...');
  });

答案 1 :(得分:1)

With Express 5.0 we have another solution :

express = require( 'express' ), //Web framework

// Solution 
express.request.__proto__ = http2.IncomingMessage.prototype;
express.response.__proto__ = http2.ServerResponse.prototype;

// Create app for server http/2
var apph2 = express();

And this is the server code :

var
    application_root = __dirname,
    express     = require( 'express' ), //Web framework
    http2       = require('http2')
    logger      = require('morgan')
    fs          = require('fs')
    constants   = require('constants');


// Bunyan logger
var bunyan = require('bunyan');
var app = require('./apps/app_name');

var bunlog = bunyan.createLogger({name: "brqx_app"});


var credentials = {
//  log         : bunlog ,  
    key         : fs.readFileSync('/etc/letsencrypt/live/domain/privkey.pem'    ),
    cert        : fs.readFileSync('/etc/letsencrypt/live/domain/fullchain.pem'  ),
    ca          : fs.readFileSync("/etc/letsencrypt/live/domain/chain.pem"      ),
    dhparam     : fs.readFileSync("/etc/letsencrypt/archive/domain/dh1.pem"     ),
    secureOptions: constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_SSLv2
};

// Configure server

server = http2.createServer( credentials , app);

 server.listen(PORT , function () {
   console.log('Started Brqx http/2!');
} )

I hope these easy lines helps to people.

One thing is important when we search information on Internet is the date of test when code was tested : 2017 - October.

Regards.

Ricardo/Brqx.