Skip to content

Instantly share code, notes, and snippets.

@inian

inian/hapi.js

Last active Aug 30, 2019
Embed
What would you like to do?
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