sandstorm-io / vagrant-spk

Packaging tool for Sandstorm, a self-hosting platform for web apps!
Apache License 2.0
55 stars 29 forks source link

Add a simple method to add powerbox-http-proxy #296

Open ocdtrekkie opened 3 years ago

ocdtrekkie commented 3 years ago

While I know it isn't "the best way to do network access", it's at minimum a good way to get a working prototype, and for stacks like lemp and lesp, very possibly "the best way for now" because I don't think there's good options or samples otherwise for interacting with capnp via PHP. I spent some time trying to get the powerbox-http-proxy working with a simple PHP app last night, and had some manner of difficulty, and I ended up grabbing a lot of "seems like I need this" from the TTRSS port to try and get it set up.

While in the ideal case, I'd love to have #227 or something like vagrant-spk add powerbox-http-proxy, I think even having commented out blocks of code that will get the powerbox-http-proxy running might be an adequate solution.

zenhack commented 3 years ago

In the short term, this might be a case of "add examples to the powerbox-http-proxy docs," which I am happy to accept patches for based on your experiences.

I too would like a more composable setup, but I think probably the way to go there is something like nix or guix, where you already have a fairly programmable packaging system, rather than having to invent from scratch mechanisms for doing things in a modular way.

But yes, there's no PHP capnproto implementation/binding. If there was, would you use it?

ocdtrekkie commented 3 years ago

@zenhack I think I would need probably A. the implementation/binding and B. sample code to make and utilize a request for outside HTTP. In both the app I am playing with currently and the other app I'd like to move to Sandstorm, I'd be talking to 4-5 domains that would be included in the app's code. (For example, I am trying to implement a basic package tracking app, so it would need to talk to UPS, FedEx, USPS APIs, not arbitrary ones the user might add like TTRSS.)

I haven't actually gotten it working yet, and I am not sure where the hangup is. (I am getting a getaddrinfo failure, as if there is no DNS, actually... maybe not unlike gischer's issue on the main repo.) But things like the websocket config in nginx.conf and adding the correct startup process in the vagrant-spk scripts may be better "in-place" for vagrant-spk rather than the generic documentation that one might use to use powerbox-http-proxy in an app built any other way.

zenhack commented 3 years ago

Note that you probably don't need PHP-capnp to do that, since the powerbox request still happens in client-side JS, and the bridge can just accept the token in a header and do the proxing for you: note that the server side of https://github.com/zenhack/hello-sandstorm-oauth/ doesn't actually use capnp at runtime, so you could just as well do that in PHP.

zenhack commented 3 years ago

Note also that it's a little hard to provide simple cookie-cutter instructions for integrating powerbox-http-proxy with an arbitrary app, because:

  1. It necessarily requires patching the client-side code to include the js bits of powerbox-http-proxy. Exactly where this goes is going to vary from app to app, but will generally take the form of adding a <script> tag ...somewhere...
  2. You also need to spoof the CA certs so the app will trust powerbox-http-proxy for TLS. This is likely to require stack-specific tweaks.
zenhack commented 3 years ago

I added a config snippet for nginx to the README -- that bit is fairly cookie-cutter in any case.

ocdtrekkie commented 3 years ago

I think my idea was maybe to have a lemp-plus-proxy stack maybe, that would have any PHP-specific config ready to go, such that one only had to add the script tag. But I also haven't gotten my test attempt to work yet.