Skip to content

Commit

Permalink
deploy: allow clients to override how they are routed with `route_ove…
Browse files Browse the repository at this point in the history
…rride` cookie (#1583)
  • Loading branch information
dyc3 authored Mar 31, 2024
1 parent 7ba3c23 commit c3a72cd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion deploy/nginx.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ map $http_upgrade $connection_upgrade {
'' close;
}

# this allows us to override the upstream based on a cookie called `route_override`
map $cookie_route_override $upstream_override {
default $split_upstream;
monolith _monolith;
balancer _balancer;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=1000m inactive=600m;

server {
Expand All @@ -25,7 +32,7 @@ server {
http2 on;

location / {
proxy_pass http://$split_upstream$request_uri;
proxy_pass http://$upstream_override$request_uri;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
Expand All @@ -42,5 +49,7 @@ server {
proxy_send_timeout 7d;

proxy_socket_keepalive on;

add_header X-Upstream $upstream_override;
}
}

0 comments on commit c3a72cd

Please sign in to comment.