Skip to content
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

Support for nodejs #59

Closed
rukor opened this issue Jun 4, 2015 · 6 comments
Closed

Support for nodejs #59

rukor opened this issue Jun 4, 2015 · 6 comments

Comments

@rukor
Copy link

rukor commented Jun 4, 2015

Is there planned support for cljs running under nodejs (in a server environment) ?

Thanks

@r0man
Copy link
Owner

r0man commented Jun 4, 2015

No, noting planned. Patch welcome!

@rukor
Copy link
Author

rukor commented Jun 4, 2015

Thanks, I will take a look.

@rukor rukor closed this as completed Jun 4, 2015
@moea
Copy link

moea commented Nov 16, 2015

Assuming the presence of the "xmlhttprequest" NPM package (e.g. via lein-npm), then this works fine: https://gist.github.com/moea/63d7a882e4ad333f3b5a

Performing that kind of global adjustment is obviously a less-good idea in a library intended for reuse. If there was interest in including something similar, I think the lowest-impact approach would be to include an xhr-factory function, which takes in a function, and returns a class like the one linked above, with the input parameter serving as the implementation of the createInstance method. Additionally, requests could support something like a :cljs-http/xhr-factory key in request maps, which will pass the option to XhrIo. And/or a (cljs-http.core/set-xhr-factory!) function which sets the factory for all requests originating via cljs-http. The code for a Node user would be something like:

(require '[cljs.nodejs :as nodejs])
(require '[cljs-http.core :as http])

(def xhr (.-XMLHttpRequest (nodejs/require "xmlhttprequest"))

(http/set-xhr-factory! (http/xhr-factory #(xhr.)))

;; use library normally

Which isn't too bad, and doesn't require there to be anything vaguely Node-specific in cljs-http.

@vikeri
Copy link

vikeri commented Feb 17, 2016

I would find an implemented version of this very useful as well. HTTP(S) + Node + CLJS seems like a pretty common/powerful usecase?

@moea
Copy link

moea commented Mar 1, 2016

@vikeri Maybe this is helpful meanwhile https://github.com/nervous-systems/kvlt

@vikeri
Copy link

vikeri commented Mar 1, 2016

I managed to get it working. But kvit seems to be a great project! I'm starting to work with React Native so this possibly comes in handy there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants