Skip to content

folder ​

folder serves files from a directory. It can also provide directory browsing, SPA fallback, path rewrites, and cache headers.

yaml
server:
  http:
    middlewares:
      docs:
        folder:
          path: ./dist
          index: true
          spa: true
          browse: false
          cache_regex:
            - regex: .*
              cache_control: no-cache

Fields ​

FieldDefaultDescription
base_path/Base path used by the browse UI.
pathFilesystem path to serve.
indexfalseServe index_name for directory requests when it exists.
strip_index_namefalseRedirect /index.html to /.
index_nameindex.htmlIndex file name.
spafalseServe the SPA index for missing non-file paths.
spa_enable_filefalseAlso serve the SPA index for missing paths that look like files.
spa_indexindex_nameSPA fallback file.
spa_index_regexRegex replacements that choose the SPA index from the URL path.
browsefalseEnable directory listing.
utcfalseRender browse timestamps in UTC.
prefix_pathPrefix stripped before filesystem lookup.
file_path_regexRegex replacements applied to the cleaned filesystem path.
cache_regexRegex-based Cache-Control rules.
browse_cacheno-cacheCache-Control value for browse pages.
disable_folder_slash_redirectfalseDisable automatic slash redirect for directories.
etagETag generation for files: weak or strong. Empty disables it.

ETag ​

When etag is set, served files get an ETag header and conditional requests (If-None-Match, If-Match, If-Range) are answered with 304 Not Modified / 412 as appropriate.

ModeValueNotes
weakW/"<modtime>-<size>"Cheap, no file read. Skipped for filesystems without a modification time.
strong"<sha256 of content>"Content hash, cached per file path, modification time and size. Works for embedded filesystems.
yaml
folder:
  path: ./dist
  etag: strong
  cache_regex:
    - regex: index\.html$
      cache_control: no-cache

Last-Modified / If-Modified-Since keep working independently of this setting.

Versioned Docs Example ​

yaml
folder:
  path: ./site
  spa: true
  index: true
  spa_index_regex:
    - regex: ^/docs/([^/]*)/.*$
      replacement: /$1/index.html
  file_path_regex:
    - regex: ^/docs/([^/]*)/?(.*)$
      replacement: /$1/latest/$2