Skip to content

net/http: recommend a polyfill for node.js #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
broady opened this issue Sep 16, 2016 · 4 comments
Closed

net/http: recommend a polyfill for node.js #518

broady opened this issue Sep 16, 2016 · 4 comments

Comments

@broady
Copy link

broady commented Sep 16, 2016

xmlhttprequest doesn't work very well:
https://www.npmjs.com/package/xmlhttprequest

For some reason the first thing it does when it gets a request is abort it. wtf?!?!?

  this.open = function(method, url, async, user, password) {
    this.abort();
    errorFlag = false;
@dmitshur
Copy link
Member

dmitshur commented Sep 19, 2016

If there's an overall better replacement for xmlhttprequest, we should be able to update to one. We'll take PRs. :)

@neelance
Copy link
Member

Note: GopherJS's support for Node.js is only intended for package testing. For every normal workload it should be preferable to simply use normal Go.

No suggestions on a polyfill, sorry.

@MartinSahlen
Copy link

@broady You are not alone! I have tried an erred somewhat with this. Background: I am currently working on porting google cloud functions to many different languages, including clojure, f# and now golang:

Back to the matter at hand: I tried

For the fetch API. I also had to include https://www.npmjs.com/package/web-streams-polyfill to satisfy

case js.Global.Get("fetch") != js.Undefined && js.Global.Get("ReadableStream") != js.Undefined: // ReadableStream is used as a check for support of streaming response bodies, see https://fetch.spec.whatwg.org/#streams.
demand for this to be present. However, none of this worked. so I tried https://github.com/driverdan/node-XMLHttpRequest. However, this just aborted and caused and endless loop of retries.

I did have a lot more success with https://github.com/pwnall/node-xhr2 that worked and seems to be stable so far. My approach was to use create a file called polyfill.js (https://github.com/MartinSahlen/go-cloud-fn/blob/master/polyfill/polyfill.js) that imported the modules i needed and then use https://github.com/webpack/webpack to bundle all dependences into a standalone file (gopherjs doesnt handle this for us it seems, and no hard feelings, there are other tools doing that already).

Final notes: So, I know gopherjs isnt meant to do this but at least this shows that it certainly is able to do it. The reason for me wanting this that is that google cloud functions currently are basically just handlers for the node express framework (and I love go ❤️ ). Maybe at some point it will work with node.js. I will be happy to discuss this further and contribute if there is a need and wish for it!

@dmitshur
Copy link
Member

dmitshur commented Mar 1, 2017

Even though this issue was closed, a similar issue #586 was later opened and there's some additional discussion/searches for a good polyfill there.

Let's continue any discussion in the open issue #586, but I just wanted to point that out for anyone following this issue, and for posterity.

@gopherjs gopherjs locked and limited conversation to collaborators Mar 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants