Skip to content

Commit

Permalink
Fix extracting cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Nov 19, 2024
1 parent 95b2298 commit 9371c1f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions {{cookiecutter.project_slug}}/docker/content/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ upstream mesop_backend {

}

map $cookie_fly_machine_id $sticky_action {
# Extract fly-machine-id cookie value
map $http_cookie $fly_machine_id {
"~*fly-machine-id=([^;]+)" $1;
default "";
}

# Determine action based on cookie value
map $fly_machine_id $sticky_action {
"" "set_cookie"; # Empty cookie - need to set it
$FLY_MACHINE_ID "proceed"; # Cookie matches current instance
default "replay"; # Cookie exists but doesn't match - need to replay
Expand All @@ -29,7 +36,7 @@ server {

# Handle replay
if ($sticky_action = "replay") {
add_header Fly-Replay "instance=$cookie_fly_machine_id";
add_header Fly-Replay "instance=$fly_machine_id";
return 307;
}

Expand Down

0 comments on commit 9371c1f

Please sign in to comment.