# Apache site for the Docker API on 127.0.0.1:4000.
# Replace meet.example.com and the certificate paths, then enable the site.
# Required modules: proxy proxy_http proxy_wstunnel rewrite ssl headers

<VirtualHost *:80>
  ServerName meet.example.com
  RewriteEngine On
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

<VirtualHost *:443>
  ServerName meet.example.com
  DocumentRoot /var/www/videocall

  SSLEngine on
  SSLCertificateFile /etc/letsencrypt/live/meet.example.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/meet.example.com/privkey.pem

  ProxyPreserveHost On
  ProxyTimeout 3600
  RequestHeader set X-Forwarded-Proto "https"

  ProxyPass /api/ http://127.0.0.1:4000/api/
  ProxyPassReverse /api/ http://127.0.0.1:4000/api/

  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /socket.io/(.*) ws://127.0.0.1:4000/socket.io/$1 [P,L]
  ProxyPass /socket.io/ http://127.0.0.1:4000/socket.io/
  ProxyPassReverse /socket.io/ http://127.0.0.1:4000/socket.io/

  RewriteCond %{REQUEST_URI} !^/api/
  RewriteCond %{REQUEST_URI} !^/socket.io/
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  RewriteRule ^ /index.html [L]

  <Directory /var/www/videocall>
    Require all granted
    Options -Indexes
  </Directory>
</VirtualHost>
