<VirtualHost *:443>
    ServerName ro-th.online
    DocumentRoot /var/www/html/ro-th-online/main
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/ro-th.online/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/ro-th.online/privkey.pem
    SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1

    Alias /test-apk/ /var/www/html/test-apk/
    <Directory /var/www/html/test-apk>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
        AddType application/vnd.android.package-archive .apk
        <FilesMatch "^(RagnarokMobilePreview\.apk(\.sha256)?|latest\.json(\.gz)?)$">
            Header set Cache-Control "no-cache"
        </FilesMatch>
    </Directory>

    RedirectMatch 302 ^/browser$ /browser/
    RedirectMatch 302 ^/Mobile$ /Mobile/
    Alias /browser/ /var/www/html/ro-th-online/public/
    Alias /Mobile/Build/ /var/www/html/ro-th-online/public/Build/
    Alias /Mobile/TemplateData/ /var/www/html/ro-th-online/public/TemplateData/
    Alias /Mobile/ /var/www/html/ro-th-online/mobile/
    <LocationMatch "^/browser(?:/|$)">
        AuthType Basic
        AuthName "Ro-Thailand browser owner"
        AuthBasicProvider file
        AuthUserFile /etc/apache2/ro-th-online-browser.htpasswd
        Require valid-user
    </LocationMatch>

    ProxyPass /bridge/ ws://127.0.0.1:8088/bridge/ retry=0
    ProxyPassReverse /bridge/ ws://127.0.0.1:8088/bridge/
    ProxyPass /content/ http://127.0.0.1:8088/content/ retry=0
    ProxyPassReverse /content/ http://127.0.0.1:8088/content/
    RewriteEngine On
    RewriteRule ^/$ - [R=404,L]
    RewriteRule ^/api/v1/(login|register|availability)$ /ro-thailand-app-api/index.php/v1/$1 [PT,L]
    Alias /ro-thailand-app-api/ /var/www/https-storefront-root/ro-thailand-app-api/
    <Directory /var/www/https-storefront-root/ro-thailand-app-api>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        AcceptPathInfo On
        Require all granted
    </Directory>

    <Directory /var/www/html/ro-th-online/main>
        Options -Indexes -FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    <Directory /var/www/html/ro-th-online/mobile>
        Options -Indexes -FollowSymLinks
        AllowOverride None
        Require all granted
        DirectoryIndex index.html
        AddType application/manifest+json .webmanifest
        Header set Cache-Control "no-cache"
    </Directory>
    <Directory /var/www/html/ro-th-online/public>
        Options -Indexes -FollowSymLinks
        AllowOverride None
        Require all granted
        DirectoryIndex index.html
        AddType application/wasm .wasm
        AddType application/octet-stream .data
        Header set Cache-Control "no-cache"
        <FilesMatch "^WebPreview\.data\.(35069e10|3f45337d|da95c328|03a0917b|aa66a9a2|a2c2a9eb|9ba5bb8b|826cbfde|95c25684|811e8f5c|9d542757|6ee5bb31|2ec36b61)\.br$">
            SetEnv no-gzip 1
            Header set Content-Encoding "br"
            Header set Content-Type "application/octet-stream"
            Header set Cache-Control "public, max-age=31536000, immutable"
        </FilesMatch>
        <FilesMatch "^WebPreview\.data\.(3f45337d|da95c328|03a0917b|aa66a9a2|a2c2a9eb|9ba5bb8b|826cbfde|95c25684|811e8f5c|9d542757|6ee5bb31|2ec36b61)\.part[0-9]{3}\.gz$">
            SetEnv no-gzip 1
            Header set Content-Encoding "gzip"
            Header set Content-Type "application/octet-stream"
            Header set Cache-Control "public, max-age=31536000, immutable"
        </FilesMatch>
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/ro-th-download-error.log
    CustomLog ${APACHE_LOG_DIR}/ro-th-download-access.log combined
</VirtualHost>
