Last active
November 10, 2017 19:36
-
-
Save vitkarpov/bc5df44b78ba38896ae2f434659685f3 to your computer and use it in GitHub Desktop.
Example of http/2 landed in Node.js 9 without --expose-http2 flag
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 http2 = require('http2'); | |
const fs = require('fs'); | |
const server = http2.createSecureServer({ | |
key: fs.readFileSync('key.pem'), | |
cert: fs.readFileSync('cert.pem') | |
}); | |
server.on('error', (err) => console.error(err)); | |
server.on('socketError', (err) => console.error(err)); | |
server.on('stream', (stream, headers) => { | |
// stream is a Duplex | |
stream.respond({ | |
'content-type': 'text/html', | |
':status': 200 | |
}); | |
stream.end('<h1>Hello World</h1>'); | |
}); | |
server.listen(8443); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment