Created
December 24, 2019 06:12
-
-
Save ryanlid/9f63a22f30222e8b351d24e370d4649c to your computer and use it in GitHub Desktop.
HTTP2 Server by Node.js
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('./cert/domain.key'), | |
cert: fs.readFileSync('./cert/domain.pem') | |
}); | |
server.on('error', (err) => console.log(err)); | |
server.on('stream', (stream, header) => { | |
// 向客户端发送响应头信息 | |
stream.respond({ | |
'content-type': 'text/html', | |
':status': 200 | |
}); | |
// 向客户端发送文件内容,并结束请求 | |
stream.end('<h1>Hello HTTP2</h1>') | |
}) | |
server.listen(443); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment