Closed konklone closed 9 years ago
/cc @vzvenyach
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"}
.
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/.
That sounds like an ace idea!
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.
It seems like the only FEC-specific stuff here could be captured in environment variables.