# Apache won't be able to resolve its own hostname, so we sneak this
# into the global context to silence a confusing-to-user warning on
# server start.
ServerName hg

<VirtualHost *:80>
  ServerName hgweb

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  # These headers need to be set or else Anubis will
  # throw an "admin misconfiguration" error.
  RequestHeader set "X-Real-Ip" "expr=%{REMOTE_ADDR}"
  RequestHeader set "X-Forwarded-Proto" "expr=%{REQUEST_SCHEME}"
  RequestHeader set "X-Http-Version" "%{SERVER_PROTOCOL}s"

  ProxyPreserveHost On

  # Anubis is listening on this address.
  ProxyPass / http://[::1]:8923/
  ProxyPassReverse / http://[::1]:8923/
</VirtualHost>

# Sneak this directive into the global context.
Listen [::1]:3001

<VirtualHost *:3001>
  ServerName hgweb

  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  WSGIDaemonProcess hg processes=${WSGI_PROCESSES} threads=${WSGI_THREADS} maximum-requests=${WSGI_MAX_REQUESTS} user=www-data group=www-data display-name=hg-wsgi
  WSGIProcessGroup hg

  WSGIScriptAlias / /var/hg/htdocs/hgweb.wsgi

  <Directory /var/hg/htdocs>
    <Files hgweb.wsgi>
      Require all granted
    </Files>
  </Directory>

  Alias /static/ /var/hg/install/lib/python3.11/site-packages/mercurial/templates/static/
  <Directory /var/hg/install/lib/python3.11/site-packages/mercurial/templates/static>
    Options -Indexes
    Require all granted
  </Directory>

  Redirect 301 /favicon.ico /static/hgicon.png
</VirtualHost>
