server {
  listen 80;
  server_name _;

  gzip on;
  gzip_comp_level 6;
  gzip_min_length 1024;
  gzip_vary on;
  gzip_types
    application/javascript
    application/json
    application/manifest+json
    application/wasm
    image/svg+xml
    text/css
    text/plain;

  etag on;

  root /usr/share/nginx/html;
  index index.html;
  client_max_body_size 25m;

  location = /index.html {
    add_header Cache-Control "no-cache" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;
    try_files /index.html =404;
  }

  location ~* ^/(bootstrap\.js|sw\.js|config\.js)$ {
    add_header Cache-Control "no-cache" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;
    try_files $uri =404;
  }

  location ~* ^/(manifest\.json|version\.json)$ {
    add_header Cache-Control "no-cache" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;
    try_files $uri =404;
  }

  location ~* ^/(flutter_service_worker\.js|flutter_bootstrap\.js|flutter\.js)$ {
    add_header Cache-Control "no-cache" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;
    return 410;
  }

  location = /graphql {
    proxy_pass https://api.map.craftee.vn/graphql;
    proxy_ssl_server_name on;
    proxy_http_version 1.1;
    proxy_set_header Host api.map.craftee.vn;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

  location /telegram/ {
    proxy_pass https://api.map.craftee.vn/telegram/;
    proxy_ssl_server_name on;
    proxy_http_version 1.1;
    proxy_set_header Host api.map.craftee.vn;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

  location ~* ^/assets/.*\.(otf|ttf|woff|woff2)$ {
    add_header Cache-Control "public, max-age=31536000, immutable" always;
    add_header Access-Control-Allow-Origin "*" always;
    types {
      font/otf otf;
      font/ttf ttf;
      font/woff woff;
      font/woff2 woff2;
    }
    try_files $uri =404;
  }

  location ~* ^/(assets|canvaskit|icons)/ {
    add_header Cache-Control "public, max-age=31536000, immutable" always;
    try_files $uri =404;
  }

  location = /main.dart.js {
    add_header Cache-Control "no-cache" always;
    add_header Pragma "no-cache" always;
    add_header Expires "0" always;
    try_files /main.dart.js =404;
  }

  location ~* \.(js|mjs|wasm|json|png|jpg|jpeg|gif|webp|svg|ico|woff|woff2|ttf)$ {
    add_header Cache-Control "public, max-age=31536000, immutable" always;
    try_files $uri =404;
  }

  location / {
    add_header Cache-Control "no-cache" always;
    try_files $uri $uri/ /index.html;
  }
}
