<IfModule mod_ssl.c>
<VirtualHost *:443>
  DocumentRoot /var/www/fortnox.synktek.com/frontend/build
  ServerName fortnox.synktek.com
  ServerAlias fortnox.synktek.com *.fortnox.synktek.com

  <Directory /var/www/fortnox.synktek.com/frontend/build>
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Require all granted
  </Directory>
  <Directory />
    Require all denied
  </Directory>

  LogLevel info
#  ErrorLog /var/log/apache2/fortnox.log
  ErrorLog ${APACHE_LOG_DIR}/fortnox_error.log
  CustomLog ${APACHE_LOG_DIR}/fortnox_access.log combined

  Header always add Strict-Transport-Security "max-age=15768000"

#  RewriteEngine on
#  RewriteCond ${HTTP:Upgrade} websocket [NC]
#  RewriteCond ${HTTP:Connection} upgrade [NC]
#  RewriteRule .* "wss:/localhost:3000/$1" [P,L]


#  ProxyRequests Off
#  ProxyErrorOverride Off
#  ProxyPass /api http://localhost:5000
#  ProxyPassReverse /api http://localhost:5000
#  ProxyPass / http://localhost:3000/
#  ProxyPassReverse / http://localhost:3000/



  # SPA fallback
  #RewriteEngine On
  #RewriteCond %{REQUEST_URI} !^/api
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteRule ^ /index.html [L]


  # SPA fallback (do NOT rewrite api or static assets)
  RewriteEngine On

  RewriteCond %{REQUEST_URI} !^/api(/|$)
  RewriteCond %{REQUEST_URI} !^/static/

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



  # API reverse proxy
  ProxyPreserveHost On
  ProxyPass /api/ http://127.0.0.1:8000/
  ProxyPassReverse /api/ http://127.0.0.1:8000/






  SSLCertificateFile /etc/letsencrypt/live/fortnox.synktek.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/fortnox.synktek.com/privkey.pem
  Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
