Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hapi and Support of HTTP/2 #2510

Closed
jmorille opened this issue Apr 21, 2015 · 9 comments
Closed

Hapi and Support of HTTP/2 #2510

jmorille opened this issue Apr 21, 2015 · 9 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@jmorille
Copy link

Hello,

Does Hapy have any support of HTTP/2 in natif or by plugins ?

Thank by advance

@hueniverse
Copy link
Contributor

You can provide your own server implementation when creating a connection using the listener option https://github.com/hapijs/hapi/blob/master/API.md#serverconnectionoptions.

@hueniverse hueniverse added the support Questions, discussions, and general support label Apr 21, 2015
@hueniverse hueniverse self-assigned this Apr 21, 2015
@AdriVanHoudt
Copy link
Contributor

This comes down to: you can provide your own http2 node server implementation until node/iojs implements it right?

@jmorille
Copy link
Author

jmorille commented May 7, 2015

it is working like express ?

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

@jmorille
Copy link
Author

jmorille commented May 7, 2015

It not work like as if I looked the socket.io sample
http://matt-harrison.com/using-hapi-js-with-socket-io/

I will try it with node-http2 module..

@peterhanneman
Copy link

I couldn't find any resources online with a direct explanation of how to implement HTTP2 with Hapi so I'll document my solution here:

var Fs = require('fs');
var Hapi = require('hapi');
var Http2 = require('http2');

var options = {
  key: Fs.readFileSync('./ssl/site.key');
  cert: Fs.readFileSync('./ssl/site.crt');
};

var server = new Hapi.Server();
server.connection({
   listener: Http2.createServer(options),
   host: 'localhost',
   port: 8080,
   tls: true
});

It would appear that Socket.io is NOT yet compatible with the HTTP2 library. I've submitted a bug report. The workaround is serving Socket.io from another connection with the usual HTTPS listener.

@casalot
Copy link

casalot commented Jan 15, 2016

@timelessvirtues, I've tried your sample above, but I keep getting a self.listener.address is not a function. Any ideas?

@mikefrey
Copy link
Contributor

@casalot I had luck doing this:

'use strict'
const fs = require('fs')
const Hapi = require('hapi')
const Http2 = require('http2')
const server = new Hapi.Server()

let listener = Http2.createServer({
  key: fs.readFileSync('./key.pem'),
  cert: fs.readFileSync('./cert.pem')
})

if (!listener.address) {
  listener.address = function() {
    return this._server.address()
  }
}

server.connection({
  listener: listener,
  port: '8000',
  tls: true
})

server.route({
  method: 'GET',
  path: '/',
  handler: (request, reply) => reply('hello world')
})

server.start(err => {
  if (err) console.error(err)
  console.log(`Started ${server.connections.length} connections`)
})

@penumakauday
Copy link

Hi, I am trying to add the https config tls to manifest js as below

connections: [{
host: {
$filter: 'env',
production: process.env.HOST,
$default: '0.0.0.0'
},
port: {
$filter: 'env',
production: process.env.PORT,
$default: 3000

},
tls:{
key : fs.readFileSync('testkey.pem'),
cert : fs.readFileSync('testcert.pem')
}}]

But https server is not getting started. Could anyone help me on fixing this.

@Marsup
Copy link
Contributor

Marsup commented Mar 18, 2016

Please avoid hijacking unrelated threads when you already have yours.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

8 participants