Skip to content

Instantly share code, notes, and snippets.

@inian
Last active August 30, 2019 04:15
Show Gist options
  • Save inian/06e9b87ccc8f7967464b7de632970a99 to your computer and use it in GitHub Desktop.
Save inian/06e9b87ccc8f7967464b7de632970a99 to your computer and use it in GitHub Desktop.
Node Frameworks using http2
var fs = require('fs');
var Hapi = require('hapi');
var http2 = require('http2');
var options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
};
var server = new Hapi.Server();
server.connection({
listener: http2.createSecureServer(options),
host: 'localhost',
port: 443,
tls: true
});
server.route({
method: 'GET',
path:'/hello',
handler: function (request, reply) {
return reply('hello world');
}
});
server.start(err => {
if (err) console.error(err)
console.log(`Started ${server.connections.length} connections`)
})
const fs = require('fs');
const http2 = require('http2');
const koa = require('koa');
const options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
};
const app = new koa();
// response
app.use(ctx => {
ctx.body = 'Hello Koa';
});
const server = http2.createSecureServer(options, app.callback());
server.listen(443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment