Commit 418a9b0b authored by Terence Lee's avatar Terence Lee

make the trailing slash in proxies' origin optional in static.json

parent 70578df9
......@@ -18,6 +18,11 @@ class NginxConfig
json["port"] ||= ENV["PORT"] || 5000
json["root"] ||= "public_html/"
json["proxies"] ||= {}
json["proxies"].each do |loc, hash|
if hash["origin"][-1] != "/"
json["proxies"][loc].merge!("origin" => hash["origin"] + "/")
end
end
json["clean_urls"] ||= false
json["routes"] ||= {}
json["routes"] = Hash[json["routes"].map { |route, target| [to_regex(route), target] }]
......
......@@ -85,19 +85,22 @@ RSpec.describe "Simple" do
describe "proxies" do
include PathHelper
let(:name) { "proxies" }
let(:static_json_path) { fixtures_path("proxies/static.json") }
before do
let(:name) { "proxies" }
let(:static_json_path) { fixtures_path("proxies/static.json") }
let(:setup_static_json) do
Proc.new do |path|
File.open(static_json_path, "w") do |file|
file.puts <<STATIC_JSON
{
"proxies": {
"/api/": {
"origin": "http://#{AppRunner::HOST_IP}:#{AppRunner::HOST_PORT}/foo/"
"origin": "http://#{AppRunner::HOST_IP}:#{AppRunner::HOST_PORT}#{path}"
}
}
}
STATIC_JSON
end
end
end
......@@ -105,10 +108,28 @@ STATIC_JSON
FileUtils.rm(static_json_path)
end
it "should proxy requests" do
response = app.get("/api/bar/")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("api")
context "trailing slash" do
before do
setup_static_json.call("/foo/")
end
it "should proxy requests" do
response = app.get("/api/bar/")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("api")
end
end
context "without a trailing slash" do
before do
setup_static_json.call("/foo")
end
it "should proxy requests" do
response = app.get("/api/bar/")
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("api")
end
end
end
end
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