particle-api-js
particle-api-js copied to clipboard
unable to define a proxy
I would like to push events and listen to event streams from a server inside a corporate proxy. From what I can gather from the code, there's no current way to define proxy settings for the requests the lib is doing to the particle cloud api.
It seems like for normal functions within the Particle module, superagent-proxy (https://github.com/TooTallNate/superagent-proxy) and a configurable flag could solve it, since it uses superagent for the requests. For EventStream it will be trickier since it uses default node http/https libraries. I've implemented the EventStream solution using request and setting the proxy there.
I think your best bet is to look at the cloud API documentation https://docs.particle.io/reference/api/ and write code to access those HTTP endpoints through your proxy. It sounds like wrapping the particle-api-js module in a proxy module would be harder than wiring a couple HTTP calls from scratch.
Basically I have stopped using this library and am doing the HTTP calls myself. That being said, this library provides a nice DSL, and some good practices around error handling and handling streams, which I would have to re-implement, and which I would love to avoid. Also, I imagine this library will continue to evolve as the api evolves, and so having the ability to just update this and be compatible with latest api would be great. If there's interest, I can try and work on a pull-request.
Sure, if you'd like to investigate how to support proxies, go ahead. I'd love to see a pull request that adds the ability to inject additional superagent plugins, and puts information in the readme on how to add a proxy plugin.
I would recommend avoiding request
. We specifically switched away from it because it is too heavy for a library that needs to run in the browser.