Commit 6c0368e5 authored by Terence Lee's avatar Terence Lee Committed by GitHub

Merge pull request #36 from heroku/jmervine-interpolate-redirects

adding interpolation to redirects
parents 9ff0c2cd ce97bead
......@@ -82,6 +82,25 @@ With custom redirects, you can move pages to new routes but still preserve the o
}
```
##### Interpolating Env Var Values
It's common to want to be able to test the frontend against various backends. The `url` key supports environment variable substitution using `${ENV_VAR_NAME}`. For instance, if there was a staging and production Heroku app for your API, you could setup the config above like the following:
```json
{
"redirects": {
"/old/gone/": {
"url": "${NEW_SITE_DOMAIN}/new/here/"
}
}
}
```
Then using the [config vars](https://devcenter.heroku.com/articles/config-vars), you can point the frontend app to the appropriate backend. To match the original proxy setup:
```bash
$ heroku config:set NEW_SITE_DOMAIN="https://example.herokapp.com"
```
#### Custom Error Pages
You can replace the default nginx 404 and 500 error pages by defining the path to one in your config.
......
......@@ -30,11 +30,18 @@ class NginxConfig
uri.path = ""
json["proxies"][loc]["host"] = uri.to_s
end
json["clean_urls"] ||= DEFAULT[:clean_urls]
json["https_only"] ||= DEFAULT[:https_only]
json["routes"] ||= {}
json["routes"] = NginxConfigUtil.parse_routes(json["routes"])
json["redirects"] ||= {}
json["redirects"].each do |loc, hash|
json["redirects"][loc].merge!("url" => NginxConfigUtil.interpolate(hash["url"], ENV))
end
json["error_page"] ||= nil
json["debug"] ||= ENV['STATIC_DEBUG']
json.each do |key, value|
......
{
"redirects": {
"/old/gone": {
"url": "/",
"status": 302
},
"/old/interpolation": {
"url": "${INTERPOLATED_URL}",
"status": 302
}
}
}
......@@ -89,6 +89,20 @@ RSpec.describe "Simple" do
expect(response.code).to eq("302")
expect(response["location"]).to eq("http://#{AppRunner::HOST_IP}/")
end
context "interpolation" do
let(:name) { "redirects_interpolation" }
let(:env) {
{ "INTERPOLATED_URL" => "/interpolation.html" }
}
it "should redirect using interpolated urls" do
response = app.get("/old/interpolation")
expect(response.code).to eq("302")
expect(response["location"]).to eq("http://#{AppRunner::HOST_IP}/interpolation.html")
end
end
end
describe "https only" do
......
......@@ -23,14 +23,15 @@ class AppRunner
@run = false
@debug = debug
env.merge!("STATIC_DEBUG" => true) if @debug
@container = Docker::Container.create(
'Image' => BuildpackBuilder::TAG,
'Cmd' => ["bash", "-c", "cp -rf /src/* /app/ && /app/bin/boot"],
"Image" => BuildpackBuilder::TAG,
"Cmd" => ["bash", "-c", "cp -rf /src/* /app/ && /app/bin/boot"],
# Env format is [KEY1=VAL1 KEY2=VAL2]
'Env' => env.to_a.map {|i| i.join("=") },
'HostConfig' => {
'Binds' => ["#{fixtures_path(fixture)}:/src"],
'PortBindings' => {
"Env" => env.to_a.map {|i| i.join("=") },
"HostConfig" => {
"Binds" => ["#{fixtures_path(fixture)}:/src"],
"PortBindings" => {
"#{CONTAINER_PORT}/tcp" => [{
"HostIp" => HOST_IP,
"HostPort" => HOST_PORT,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment