Skip to content

Instantly share code, notes, and snippets.

@hieven
Created August 14, 2019 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieven/547368291942be8e23aebcd2147b63d7 to your computer and use it in GitHub Desktop.
Save hieven/547368291942be8e23aebcd2147b63d7 to your computer and use it in GitHub Desktop.
const http2 = require('http2')
const path = require('path')
const fs = require('fs')
const rootPath = path.resolve(__dirname, '..')
const httpServer = http2.createSecureServer(
{
key: fs.readFileSync(path.resolve(rootPath, 'cert/server.key')),
cert: fs.readFileSync(path.resolve(rootPath, 'cert/server.crt'))
},
(req, res) => {
res.statusCode = 200
res.write(`Hello HTTP/2!\n`)
res.write(`If you're using Chrome, please open Chrome Inspector and you will see the Protocol is h2 (http/2)\n`)
res.end()
}
)
httpServer.listen(3000, () => { console.log('server is listening on :3000') })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment