Last active
July 13, 2018 19:32
-
-
Save daliborgogic/273a967bedad74885965712b0ff822e2 to your computer and use it in GitHub Desktop.
Asynchronous HTTP2 microservice example
This file contains hidden or 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 h2 = require('http2') | |
const { run, send } = require('micro') | |
const cert = require('openssl-self-signed-certificate') | |
const { PORT = 3443 } = process.env | |
const options = { | |
key: cert.key, | |
cert: cert.cert, | |
passphrase: cert.passphrase | |
} | |
const microH2 = fn => h2.createSecureServer(options, (req, res) => run(req, res, fn)) | |
const server = microH2(async (req, res) => | |
send(res, 200, { encrypted: req.connection.encrypted }) | |
) | |
server.listen(PORT) |
This file contains hidden or 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
{ | |
"name": "with-h2", | |
"version": "1.0.0", | |
"scripts": { | |
"start": "node ." | |
}, | |
"dependencies": { | |
"http2": "^3.3.7", | |
"micro": "^9.3.2", | |
"openssl-self-signed-certificate": "^1.1.6" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment