Created
September 12, 2017 14:21
-
-
Save israeljrs/b15aa32451905d463606371547bf969d to your computer and use it in GitHub Desktop.
http2_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 server = http2.createSecureServer( | |
{ cert, key }, | |
onRequest | |
) | |
function push (stream, filePath) { | |
const { file, headers } = getFile(filePath) | |
const pushHeaders = { [HTTP2_HEADER_PATH]: filePath } | |
stream.pushStream(pushHeaders, (pushStream) => { | |
pushStream.respondWithFD(file, headers) | |
}) | |
} | |
function onRequest (req, res) { | |
// Push files with index.html | |
if (reqPath === '/index.html') { | |
push(res.stream, 'bundle1.js') | |
push(res.stream, 'bundle2.js') | |
} | |
// Serve file | |
res.stream.respondWithFD(file.fileDescriptor, file.headers) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment