TypeError: dest.end is not a function

I am trying to use HTTP / 2. My express version is 5.0.0-alpha.2, http2 version 3.3.4.

I suppose http2 should work well with express 5 .

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...');
  });

The server starts to work well, but when I open the client site, it gives me this error in the terminal:

_stream_readable.js:512
    dest.end();
         ^

TypeError: dest.end is not a function
    at Stream.onend (_stream_readable.js:512:10)
    at Stream.g (events.js:286:16)
    at emitNone (events.js:91:20)
    at Stream.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
+4
source share
2 answers

It seems node-http2 is not yet supported by Express. Track this issue Support for the http module on github.

At the same time, you can stay with 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...');
  });
+2

Express 5.0 :

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();

:

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!');
} )

, .

, - , : 2017 - .

.

/Brqx.

+1

Source: https://habr.com/ru/post/1652499/


All Articles