spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

http/2 Pushed javascript not loading #325

Open mattoni opened 7 years ago

mattoni commented 7 years ago

Node v8.2.1: uname -a: Linux a1da17d8416c 4.9.36-moby #1 SMP Fri Jul 14 17:47:34 UTC 2017 x86_64 Linux:

https://stackoverflow.com/questions/45251150/http-2-pushed-javascript-not-loading

I'm building an HTTP/2 server with PUSH enabled on the spdy lib. Everything works perfectly without push enabled, but when I enable it the server is pushing empty frames.

spdy .createServer(options, (req, res) => { // TODO - figure out why the javascript doesnt load on the client if (res.push) { console.log("Pushing..."); // push vendor bundle const bundleStream = res.push(/js/client.js, { status: 200, method: "GET", request: { accept: "/" }, response: { "content-type": "application/javascript" }, });

        bundleStream.on("error", (e: any) => console.error(e));
        bundleStream.end();
        // push main bundle
        const vendorStream = res.push(`/js/vendor.js`, {
            status: 200,
            method: "GET",
            request: { accept: "*/*" },
            response: { "content-type": "application/javascript" },
        });
        vendorStream.on("error", (e: any) => console.error(e));
        vendorStream.end();
    }
    return app(req as any, res as any);
})
.listen(port, (err: any) => {

The output of nghttp -nv https:// is here: https://pastebin.com/Wuju0HR2

One of the commenters on stack overflow suggested I open up an issue here. Any help is much appreciated, thanks!

GuskiS commented 7 years ago

Having the same issue. It seems that JS files are corrupted.

mattoni commented 7 years ago

Were you able to find a workaround?

threehams commented 6 years ago

Same issue with both JS and CSS.

webcarrot commented 6 years ago

Send file content:

// ...
vendorStream.on("error", (e: any) => console.error(e));
const stream = fs.createReadStream(`${somedir}/js/vendor.js`);
stream.pipe(vendorStream);
// vendorStream.end(); - fs stream end  vendorStream
// ...

or if content is Buffer/string:

// ...
vendorStream.on("error", (e: any) => console.error(e));
vendorStream.end(vendorFileBuffer)
// ...

PS. add some compression "negotiation" ( br, lzma, gzip, plain ) and serve best file prepared on build + headers...

duterte commented 3 years ago

Looks like this repository is no longer maintained