# vim: ft=nginx
map $host $code { default code; }

server {
    listen      80;
    listen      [::]:80;
    server_name code.shore.co.il;
    include     snippets/robots-disallow-all.conf;
    include     snippets/ads-txt.conf;
    include     snippets/security-txt.conf;
    include     snippets/www-acme-challenge.conf;
    include     snippets/redirect-https.conf;
}

server {
    listen      443 ssl http2;
    listen      [::]:443 ssl http2;
    server_name code.shore.co.il;
    include     snippets/robots-disallow-all.conf;
    include     snippets/ads-txt.conf;
    include     snippets/security-txt.conf;
    include     snippets/ssl-modern.conf;

    # The following was copied (and modified) from
    # https://sdk.collaboraonline.com/docs/installation/Proxy_settings.html#reverse-proxy-with-nginx-webserver.

    # static files
    location ^~ /browser {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
        proxy_hide_header       X-Frame-Options;
    }

    # WOPI discovery URL
    location ^~ /hosting/discovery {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
    }

    # Capabilities
    location ^~ /hosting/capabilities {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
    }

    # main websocket
    location ~ ^/cool/(.*)/ws$ {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
        include                 snippets/websockets.conf;
    }

    # download, presentation and image upload
    location ~ ^/(c|l)ool {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
    }

    # Admin Console websocket
    location ^~ /cool/adminws {
        proxy_pass              http://$code:9980$request_uri;
        proxy_http_version      1.1;
        include                 snippets/proxy-headers.conf;
        include                 snippets/websockets.conf;
    }
}
