Skip to content

Commit

Permalink
explore stub json and query string
Browse files Browse the repository at this point in the history
  • Loading branch information
ericminio committed Apr 26, 2024
1 parent 75fe481 commit f8aa795
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions stub-json/about/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ function test_several_endpoints {
assertequals "$body" '{ "heroes":[{ "name":"Batman", "actually":"Bruce" }, { "name":"Clark", "actually":"Superman" }] }'
}

function test_qs_based_route_one {
nginx_reload_configuration
body=$(curl http://localhost:8080/qs?path=1 | json)


assertequals "$body" '{ "one":1 }'
}

function test_qs_based_route_one {
nginx_reload_configuration
body=$(curl http://localhost:8080/qs?path=2 | json)


assertequals "$body" '{ "two":2 }'
}

20 changes: 17 additions & 3 deletions stub-json/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
map $request_body $matching {
'~one' 'one';
default 'two';
map $query_string $matching {
~path=2 'two';
default 'one';
}

server {
Expand All @@ -19,4 +19,18 @@ server {
try_files /set.json =404;
}

location /qs {
proxy_set_header 'X-Matching' $matching;
proxy_pass http://localhost/qsrouting;
}
location /qsrouting {
try_files /unknown-file-to-trigger-redirect @_$http_x_matching;
}
location @_one {
try_files /one.json =404;
}
location @_two {
try_files /two.json =404;
}

}
3 changes: 3 additions & 0 deletions stub-json/nginx/data/one.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"one": 1
}
3 changes: 3 additions & 0 deletions stub-json/nginx/data/two.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"two": 2
}

0 comments on commit f8aa795

Please sign in to comment.