passenger_default_user root;
passenger_default_group root;

passenger_log_file /dev/stdout;

passenger_ctl hook_detached_process /rails/bin/passenger-hook;

server {
  listen 3000;
  server_name smooth.fly.dev;
  port_in_redirect off;
  rewrite ^/(showcase)?$ /showcase/ redirect;
  rewrite ^/assets/ /showcase/assets/ last;

  # Authentication
  satisfy any;
  allow 127.0.0.1;
  allow ::1;

  set $realm "Showcase";
  if ($request_uri ~ "^/showcase/(assets/|cable$|docs/|password/|publish/|$)") { set $realm off; }
  if ($request_uri ~ "^/showcase/(2023/(annapolis/(medalball|chesapeakeclassic|gratitudegala)|durham|harrisburg|raleigh|richmond|vabeach)|2022/(annapolis/(medalball|chesapeakeclassic|gratitudegala)|cary|harrisburg|vabeach))/cable$") { set $realm off; }
  if ($request_uri ~ "^/showcase/[-\w]+\.\w+$") { set $realm off; }
  if ($request_uri ~ "^/showcase/\d+/\w+/(\w+/)?public/") { set $realm off; }
  auth_basic $realm;
  auth_basic_user_file /data/db/htpasswd;

  # Configuration common to all apps
  client_max_body_size 1G;
  passenger_enabled on;
  passenger_ruby /usr/local/bin/ruby;
  passenger_friendly_error_pages on;
  passenger_min_instances 0;
  passenger_set_header X-Request-Id $request_id;
  passenger_env_var GEM_HOME /usr/local/bundle;
  passenger_env_var RAILS_RELATIVE_URL_ROOT /showcase;
  passenger_env_var RAILS_APP_REDIS showcase_production;

  # index
  location /showcase/ {
    root /rails/public;
    passenger_app_group_name showcase-index;
    passenger_env_var RAILS_APP_OWNER "index";
    passenger_env_var DATABASE_URL sqlite3:///data/db/index.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/index;
    passenger_env_var RAILS_APP_DB index;
    passenger_env_var RAILS_SERVE_STATIC_FILES true;
    passenger_base_uri /;
    passenger_env_var PIDFILE /rails/tmp/pids/index.pid;
  }

  # Annapolis - Metal Ball
  rewrite /showcase/2023/annapolis/medalball/cable /showcase/cable last;
  location /showcase/2023/annapolis/medalball {
    root /rails/public;
    passenger_app_group_name showcase-2023-annapolis-medalball;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-annapolis-medalball.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-annapolis-medalball;
    passenger_env_var RAILS_APP_DB 2023-annapolis-medalball;
    passenger_env_var RAILS_APP_SCOPE 2023/annapolis/medalball;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-annapolis-medalball.pid;
  }

  # Annapolis - Chesapeake Classic
  rewrite /showcase/2023/annapolis/chesapeakeclassic/cable /showcase/cable last;
  location /showcase/2023/annapolis/chesapeakeclassic {
    root /rails/public;
    passenger_app_group_name showcase-2023-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-annapolis-chesapeakeclassic.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_DB 2023-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_SCOPE 2023/annapolis/chesapeakeclassic;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-annapolis-chesapeakeclassic.pid;
  }

  # Annapolis - Gratitude Gala
  rewrite /showcase/2023/annapolis/gratitudegala/cable /showcase/cable last;
  location /showcase/2023/annapolis/gratitudegala {
    root /rails/public;
    passenger_app_group_name showcase-2023-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-annapolis-gratitudegala.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_DB 2023-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_SCOPE 2023/annapolis/gratitudegala;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-annapolis-gratitudegala.pid;
  }

  # Charlotte
  location /showcase/2023/charlotte {
    return 409 "wrong region\n";
    add_header Fly-Replay region=atl always;
  }

  # Chicago
  location /showcase/2023/chicago {
    return 409 "wrong region\n";
    add_header Fly-Replay region=ord always;
  }

  # Clearwater - Glass Slipper Gala
  location /showcase/2023/clearwater/glassslipper {
    return 409 "wrong region\n";
    add_header Fly-Replay region=mia always;
  }

  # Clearwater - National Dance Day
  location /showcase/2023/clearwater/nationaldance {
    return 409 "wrong region\n";
    add_header Fly-Replay region=mia always;
  }

  # Clearwater - Snowball
  location /showcase/2023/clearwater/snowball {
    return 409 "wrong region\n";
    add_header Fly-Replay region=mia always;
  }

  # Clearwater - Flamingo Opener
  location /showcase/2023/clearwater/flamingoopener {
    return 409 "wrong region\n";
    add_header Fly-Replay region=mia always;
  }

  # Durham
  rewrite /showcase/2023/durham/cable /showcase/cable last;
  location /showcase/2023/durham {
    root /rails/public;
    passenger_app_group_name showcase-2023-durham;
    passenger_env_var RAILS_APP_OWNER "Durham";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-durham.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-durham;
    passenger_env_var RAILS_APP_DB 2023-durham;
    passenger_env_var RAILS_APP_SCOPE 2023/durham;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-durham.pid;
  }

  # Glenview
  location /showcase/2023/glenview {
    return 409 "wrong region\n";
    add_header Fly-Replay region=ord always;
  }

  # Harrisburg
  rewrite /showcase/2023/harrisburg/cable /showcase/cable last;
  location /showcase/2023/harrisburg {
    root /rails/public;
    passenger_app_group_name showcase-2023-harrisburg;
    passenger_env_var RAILS_APP_OWNER "Harrisburg";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-harrisburg.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-harrisburg;
    passenger_env_var RAILS_APP_DB 2023-harrisburg;
    passenger_env_var RAILS_APP_SCOPE 2023/harrisburg;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-harrisburg.pid;
  }

  # Lakeview
  location /showcase/2023/lakeview {
    return 409 "wrong region\n";
    add_header Fly-Replay region=ord always;
  }

  # Raleigh
  rewrite /showcase/2023/raleigh/cable /showcase/cable last;
  location /showcase/2023/raleigh {
    root /rails/public;
    passenger_app_group_name showcase-2023-raleigh;
    passenger_env_var RAILS_APP_OWNER "Raleigh";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-raleigh.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-raleigh;
    passenger_env_var RAILS_APP_DB 2023-raleigh;
    passenger_env_var RAILS_APP_SCOPE 2023/raleigh;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-raleigh.pid;
  }

  # Richmond
  rewrite /showcase/2023/richmond/cable /showcase/cable last;
  location /showcase/2023/richmond {
    root /rails/public;
    passenger_app_group_name showcase-2023-richmond;
    passenger_env_var RAILS_APP_OWNER "Richmond";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-richmond.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-richmond;
    passenger_env_var RAILS_APP_DB 2023-richmond;
    passenger_env_var RAILS_APP_SCOPE 2023/richmond;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-richmond.pid;
  }

  # Sugar Land
  location /showcase/2023/sugarland {
    return 409 "wrong region\n";
    add_header Fly-Replay region=dfw always;
  }

  # Virginia Beach
  rewrite /showcase/2023/vabeach/cable /showcase/cable last;
  location /showcase/2023/vabeach {
    root /rails/public;
    passenger_app_group_name showcase-2023-vabeach;
    passenger_env_var RAILS_APP_OWNER "Virginia Beach";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2023-vabeach.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2023-vabeach;
    passenger_env_var RAILS_APP_DB 2023-vabeach;
    passenger_env_var RAILS_APP_SCOPE 2023/vabeach;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2023-vabeach.pid;
  }

  # Woodlands
  location /showcase/2023/woodlands {
    return 409 "wrong region\n";
    add_header Fly-Replay region=dfw always;
  }

  # Annapolis - Metal Ball
  rewrite /showcase/2022/annapolis/medalball/cable /showcase/cable last;
  location /showcase/2022/annapolis/medalball {
    root /rails/public;
    passenger_app_group_name showcase-2022-annapolis-medalball;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-annapolis-medalball.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-annapolis-medalball;
    passenger_env_var RAILS_APP_DB 2022-annapolis-medalball;
    passenger_env_var RAILS_APP_SCOPE 2022/annapolis/medalball;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-annapolis-medalball.pid;
  }

  # Annapolis - Chesapeake Classic
  rewrite /showcase/2022/annapolis/chesapeakeclassic/cable /showcase/cable last;
  location /showcase/2022/annapolis/chesapeakeclassic {
    root /rails/public;
    passenger_app_group_name showcase-2022-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-annapolis-chesapeakeclassic.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_DB 2022-annapolis-chesapeakeclassic;
    passenger_env_var RAILS_APP_SCOPE 2022/annapolis/chesapeakeclassic;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-annapolis-chesapeakeclassic.pid;
  }

  # Annapolis - Gratitude Gala
  rewrite /showcase/2022/annapolis/gratitudegala/cable /showcase/cable last;
  location /showcase/2022/annapolis/gratitudegala {
    root /rails/public;
    passenger_app_group_name showcase-2022-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_OWNER "Annapolis";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-annapolis-gratitudegala.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_DB 2022-annapolis-gratitudegala;
    passenger_env_var RAILS_APP_SCOPE 2022/annapolis/gratitudegala;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-annapolis-gratitudegala.pid;
  }

  # Cary
  rewrite /showcase/2022/cary/cable /showcase/cable last;
  location /showcase/2022/cary {
    root /rails/public;
    passenger_app_group_name showcase-2022-cary;
    passenger_env_var RAILS_APP_OWNER "Cary";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-cary.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-cary;
    passenger_env_var RAILS_APP_DB 2022-cary;
    passenger_env_var RAILS_APP_SCOPE 2022/cary;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-cary.pid;
  }

  # Charlotte
  location /showcase/2022/charlotte {
    return 409 "wrong region\n";
    add_header Fly-Replay region=atl always;
  }

  # Harrisburg
  rewrite /showcase/2022/harrisburg/cable /showcase/cable last;
  location /showcase/2022/harrisburg {
    root /rails/public;
    passenger_app_group_name showcase-2022-harrisburg;
    passenger_env_var RAILS_APP_OWNER "Harrisburg";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-harrisburg.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-harrisburg;
    passenger_env_var RAILS_APP_DB 2022-harrisburg;
    passenger_env_var RAILS_APP_SCOPE 2022/harrisburg;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-harrisburg.pid;
  }

  # Kennesaw
  location /showcase/2022/kennesaw {
    return 409 "wrong region\n";
    add_header Fly-Replay region=atl always;
  }

  # Virginia Beach
  rewrite /showcase/2022/vabeach/cable /showcase/cable last;
  location /showcase/2022/vabeach {
    root /rails/public;
    passenger_app_group_name showcase-2022-vabeach;
    passenger_env_var RAILS_APP_OWNER "Virginia Beach";
    passenger_env_var DATABASE_URL sqlite3:///data/db/2022-vabeach.sqlite3;
    passenger_env_var RAILS_DB_VOLUME /data/db;
    passenger_env_var RAILS_STORAGE /data/storage/2022-vabeach;
    passenger_env_var RAILS_APP_DB 2022-vabeach;
    passenger_env_var RAILS_APP_SCOPE 2022/vabeach;
    passenger_env_var SHOWCASE_LOGO arthur-murray-logo.gif;
    passenger_env_var PIDFILE /rails/tmp/pids/2022-vabeach.pid;
  }

  # Action cable (shared by all apps on this server listen port)
  location /showcase/cable {
    root /rails/public;
    passenger_app_group_name showcase-cable;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  # publish
  location /showcase/publish {
    root /rails/fly/applications/publish/public;
    passenger_app_group_name showcase-publish;
    passenger_env_var SECRET_KEY_BASE 1;
  }
}
