server {
  listen 8080;
  listen 3000;
  server_name localhost;

  server_tokens off;

  root /usr/share/nginx/html;

  add_header X-Frame-Options DENY always;

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

  location ~ "^/explorer/items/files/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
      try_files $uri /explorer/items/files/[id].html;
  }

  location ~ "^/explorer/items/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
    try_files $uri /explorer/items/[id].html;
  }

  location ~ "^/wopi/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
    try_files $uri /wopi/[id].html;
  }

  location ~ "^/user-reconciliations/(active|inactive)/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" {
    try_files $uri /user-reconciliations/$1/[id].html;
  }

  location ~ "^/explorer/items/(favorites|my-files|recent|shared-with-me)/?$" {
    try_files $uri /explorer/items/$1.html;
  }

  location ~ "^/sdk/explorer/?$" {
      try_files $uri /sdk/explorer.html;
  }

  location ~ "^/sdk/?$" {
      try_files $uri /sdk.html;
  }

  location ~ "^/explorer/trash/?$" {
    try_files $uri /explorer/trash.html;
  }

  location ~ "^/401/?$" {
    try_files $uri /401.html;
  }

  location ~ "^/403/?$" {
    try_files $uri /403.html;
  }

  error_page 404 /404.html;
  location = /404.html {
    internal;
  }

  # Without this, the .mjs file is served as application/octet-stream 
  # which breaks ES modules
  location ~* \.mjs$ {
      types { application/javascript mjs; }
      try_files $uri =404;
  }
}
