<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/
    # Preview-matched Payon interiors; these exact objects also back the APK catalog.
    ProxyPassMatch "^/content/maps/payon_in0[123]/map[.]bytes$" "!"
    AliasMatch "^/content/maps/payon_in01/map[.]bytes$" "/var/www/html/test-apk/patches/Maps/objects/f66c5b57ccb3caec41203901365679a47203d30e05ddefd2711442032e36386a"
    AliasMatch "^/content/maps/payon_in02/map[.]bytes$" "/var/www/html/test-apk/patches/Maps/objects/ddea884ba7bb593d200ee0a4a729b8bcd9f818cfcf0b554a21a253c0986d8f5a"
    AliasMatch "^/content/maps/payon_in03/map[.]bytes$" "/var/www/html/test-apk/patches/Maps/objects/434ebff2bff04fc4728c57e934d5f5ed8f41768ee729f211e76f369b7f253b2b"
    <LocationMatch "^/content/maps/payon_in0[123]/map[.]bytes$">
        ForceType application/octet-stream
        Header set Cache-Control "no-store"
    </LocationMatch>
    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|f0c5ed1b|e5b689ab|845531b1|ecb16fc5|2e980a49|659e6266|14515af5|89773500)\.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|f0c5ed1b|e5b689ab|845531b1|ecb16fc5|2e980a49|659e6266|14515af5|89773500)\.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>
