server {
  listen       80;
  server_name  localhost 127.0.0.1;

  root /usr/share/nginx/html;
  index index.html;

  # If the browser can render compressed files,
  # give it the pre-compressed version.
  gzip_static on;

  resolver $NAMESERVER;

  # We must do this indirection to prevent Nginx from forever caching the IP
  # for our API endpoint.
  # See https://distinctplace.com/2017/04/19/nginx-resolver-explained/ .

  # Set production proxy rules here. Any proxies set here must also be added
  # to the Vue config to proxy in development.

  # ##################################################################################

  set $hwsd_api_endpoint https://hwsd-gateway.zooxlabs.com;
  location /api/hwsd-gateway/ {
    rewrite ^/api/hwsd-gateway/(.*) /$1 break;
    proxy_pass $hwsd_api_endpoint;
  }

  # ##################################################################################

  location / {
    try_files $uri $uri/ /index.html;
  }

  location = /index.html {
    # Must revalidate cache.
    add_header Cache-Control max-age=0;
  }

  location ~ ^/(css|js)/ {
    # Do not try_files for /index.html.
    # Cache as long as possible.
    add_header Cache-Control "public, max-age=31536000";
  }
}
