# Include this virtual host in Apache HTTP Server 2.4 configuration.
# Set server.serveFrontend to false in the backend configuration.
# Enable HTTPS before using the CMS; see the deployment guide.
<VirtualHost *:80>
    ServerName cms.example.com
    DocumentRoot "/srv/tinycms/app/apps/frontend/dist"
    DirectoryIndex index.html
    LimitRequestBody 105906176

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyTimeout 60
    RequestHeader set X-Forwarded-Proto "expr=%{REQUEST_SCHEME}"

    <LocationMatch "^/api/v1/server(/|$)">
        Require all denied
    </LocationMatch>

    ProxyPassMatch "^/((api|resources|profile-images)(/.*)?|health)$" "http://127.0.0.1:3000/$1"
    ProxyPassReverse "/" "http://127.0.0.1:3000/"

    <Directory "/srv/tinycms/app/apps/frontend/dist">
        Options -Indexes -MultiViews
        AllowOverride None
        Require all granted
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/(api|resources|profile-images)(/|$)
        RewriteCond %{REQUEST_URI} !^/health$
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^ /index.html [END]
    </Directory>
</VirtualHost>
