Created
April 25, 2023 09:31
-
-
Save whtsky/a5db3b9609be5a5bc5e83a4bb0638eeb to your computer and use it in GitHub Desktop.
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 port = 8433; | |
const server = http2.createSecureServer({ | |
key: fs.readFileSync("localhost.key"), | |
cert: fs.readFileSync("localhost.crt"), | |
}); | |
server.on("error", (err) => console.error(err)); | |
server.on("stream", (stream, headers) => { | |
stream.respond({ | |
"content-type": "text/html; charset=utf-8", | |
":status": 200, | |
}); | |
stream.write("<p>Hello World!</p>"); | |
let i = 0; | |
const interval = setInterval(function () { | |
console.log("Write: ", i); | |
stream.write(i + "\n"); | |
i++; | |
}, 1000); | |
stream.on("close", () => { | |
clearInterval(interval); | |
}); | |
}); | |
server.listen(port, () => { | |
console.log(`HTTP/2 server running on port ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment