Last active
August 30, 2019 04:15
-
-
Save inian/06e9b87ccc8f7967464b7de632970a99 to your computer and use it in GitHub Desktop.
Node Frameworks using http2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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