5

I am trying to use HTTP/2. My express version is 5.0.0-alpha.2, http2 version is 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 running well, but when I open client website, 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
  • github.com/molnarg/node-http2/issues/100 looks like spdy is dead Commented Aug 25, 2016 at 17:10
  • @Joe thanks, I am trying to use http2 package now, but failed. That is where this question came from. Commented Aug 25, 2016 at 17:11
  • I think that the person answering the question you're referring to means that for HTTP/2 to work, you need to use the spdy module and not the http2 module. I can replicate the error you're getting, and it goes away when I use spdy.createServer(...) instead of http2.createServer(...). Commented Aug 25, 2016 at 18:38
  • @robertklep thanks, and I just found that Express 5 has not supported node-http2 yet.. Commented Aug 25, 2016 at 19:20

2 Answers 2

2

It seems node-http2 has not been supported by Express yet. Please track this issue Support for module http on github.

In the meanwhile, 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...');
  });
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.