fecgov / fec-proxy

Reverse proxy app to combine multiple applications.
Other
8 stars 6 forks source link

Could this be generic? #1

Closed konklone closed 9 years ago

konklone commented 9 years ago

It seems like the only FEC-specific stuff here could be captured in environment variables.

afeld commented 9 years ago

/cc @vzvenyach

jmcarp commented 9 years ago

Sure, how about something like this:

    <% require 'json' %>
    <% proxies = JSON.parse(ENV["PROXY_MAP"] || "{}") %>

    <% proxies.each do |path, route| %>
      location <%= path %> {
        proxy_pass <%= route %>
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
        proxy_set_header X-Script-Name <%= path %>;
      }
    <% end %>

...where PROXY_MAP is a JSON string mapping paths to URLs, like {"/": "https:/fec-dev-cms.18f.gov", "/data": "https://fec-dev-web.18f.gov"}.

jmcarp commented 9 years ago

FWIW, this setup requires that the proxied apps respect X-Script-Name. For Flask, I found a simple implementation here: http://flask.pocoo.org/snippets/35/.

konklone commented 9 years ago

That sounds like an ace idea!

jmcarp commented 9 years ago

Updated as described above. This still isn't completely generic, since the manifest with the new env vars is checked into the repo, but it's a start.