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

Ability to modify link rewriting separate from the spandx listener #19

Open
Fryguy opened this issue Aug 23, 2018 · 3 comments
Open

Ability to modify link rewriting separate from the spandx listener #19

Fryguy opened this issue Aug 23, 2018 · 3 comments

Comments

@Fryguy
Copy link

Fryguy commented Aug 23, 2018

The use case we are trying to solve is running spandx in an OpenShift Pod as one container together with another container serving part of the content. When running in a pod, it is exposed via an OpenShift Service, and ultimately outside of the cluster through an OpenShift Route. The Route defines what the link rewriting values should be as seen by the end user, but spandx needs to do it's listening with different values. An illustration can show this best

  • route: route_outside_my_cluster.example.com:443 (will route to service_inside_my_cluster:1337)
  • service: service_inside_my_cluster:1337 (will forward to pod:1337)
  • pod:
    • container1: spandx:1337 (will listen on 1337, proxy /my_app to localhost:8002, and / to static.example.com)
    • container2: partial_application:8002

From the outside I need links to be rewritten to route_outside_my_cluster.example.com:443, as that's what the end user will see, but the link rewriting use the same port value that spandx will listen on. What I end up with are the links rewritten to route_outside_my_cluster.example.com:1337. If possible, I would like the spandx config to have a way to give the rewriting rules different values.

Example config and output:

### USING SPANDX CONFIG ###
{ host: 'route_outside_my_cluster.example.com',
  port: 1337,
  routes: 
   { '/static': { host: 'https://static.example.com'  },
     '/my_app': { host: 'https://localhost:8002'  },
     '/': { host: 'https://static.example.com'  } } }
###########################
For more info see: https://github.com/redhataccess/spandx 
configuration: /spandx.config.js

Launching spandx with the following configuration
These paths will be routed to the following remote hosts
  https://route_outside_my_cluster.example.com:1337 /static will be routed to https://static.example.com /static
  https://route_outside_my_cluster.example.com:1337 /my_app will be routed to https://localhost:8002 /my_app
  https://route_outside_my_cluster.example.com:1337 / will be routed to https://static.example.com /

These paths will be routed to your local filesystem

Your browser will refresh when files change under these paths

These find/replace rules will be used to fix links in remote server responses
  /https:\/\/static.example.com/g will be replaced with "https://route_outside_my_cluster.example.com:1337 "
  /https:\/\/localhost:8002/g will be replaced with "https://route_outside_my_cluster.example.com:1337 "
  /https:\/\/static.example.com/g will be replaced with "https://route_outside_my_cluster.example.com:1337 "

spandx URL:
  https://route_outside_my_cluster.example.com:1337/ 

[Browsersync] Proxying: http://localhost:8000 
[Browsersync] Access URLs:
 ------------------------------
 Local: https://localhost:1337/ 
 ------------------------------

If I change the config's port value from 1337 to 443 to satisfy the link rewriting, then spandx will listen on 443 as well, but in an OpenShift Pod that is not allowed without requiring elevated privileges. If there were a way to separately specify spandx's listening port, then I could set the link rewriting to 443 and the listening port to 1337.

Generalized, I think this would happen with any proxy/load-balancer in front of spandx.

cc @iphands @carbonin

@mwcz
Copy link
Contributor

mwcz commented Jan 10, 2019

Interesting, what sort of solution would you propose? Would something like this work, or is this too targeted of a solution?

{ host: 'route_outside_my_cluster.example.com',
  port: 1337,
  rewritePort: 443 }

@Fryguy
Copy link
Author

Fryguy commented Jan 15, 2019

maybe? I wasn't sure if the existing "port" should be tied to the spandx listening side or the externally facing side. But once one side is chosen (as in your example you chose it to be the spandx listening side), then a second port config for the other side seems like a decent approach.

@soulless-viewer
Copy link

Hi guys. How did you solve this problem in the end?

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

3 participants