Caddyfile Generator

v1.0.2

{
  # no need for an admin interface
  admin off

  # https is done by something else
  auto_https off

  # enable prometheus metrics
  servers {
    metrics
  }
}

: {
  # Set the root directory for serving files
  root * ./app/

  # Serve all static files including HTML, CSS, JS, images, etc.
  file_server

  # Enable Server Side Includes for HTML files
  templates {
    file_extensions .html
  }

  # First, rewrite URLs with trailing slash to the same path without the slash
  @trailingSlash {
    path_regexp trailing ^(.+)/$
  }
  rewrite @trailingSlash /{http.regexp.trailing.1}

  # Try to rewrite URLs to corresponding .html files if they exist
  try_files {path}.html {path}

  encode zstd gzip

  # Handle 404 errors
  handle_errors {
    @404 {
      expression {http.error.status_code} == 404
    }
    rewrite @404 /404.html
    file_server
  }
  
  
  # rewrite the root URL to /index.html
  rewrite / /index.html
  
  # redirect the /index.html to /
  redir /index.html / 301
  redir /index / 301
  redir /index/ / 301

  # Block access to the includes directory
  @includes {
    path /includes/*
  }
  
}

# mimic the admin endpoint
:2019 {
  respond /status "I'm up!" 200
  metrics /metrics
  encode zstd gzip
}
expand_less brightness_auto