Skip to content

Instantly share code, notes, and snippets.

@ofanidariyan
Created August 20, 2017 10:57
Show Gist options
  • Save ofanidariyan/dbe70daa4c03ad1cff8a863a75b2eca0 to your computer and use it in GitHub Desktop.
Save ofanidariyan/dbe70daa4c03ad1cff8a863a75b2eca0 to your computer and use it in GitHub Desktop.
const http2 = require('http2');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 3000;
const options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt'),
requestCert: false,
rejectUnauthorized: false
};
// Create a plain-text HTTP/2 server
const server = http2.createSecureServer(options);
server.on('stream', (stream, headers) => {
stream.respond({
'content-type': 'text/html',
':status': 200
});
stream.end('Hello Word');
});
server.listen(port, hostname, () => {
console.log(`Server running at https://${hostname}:${port}/ !!!`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment