Static Sites
Railpack can automatically build and set up a server for static sites that require no build steps. The Caddy server is used as the underlying web server.
Detection
Section titled “Detection”Your project will be automatically detected as a static site if any of these conditions are met:
- A
Staticfileconfiguration file exists in the root directory - An
index.htmlfile exists in the root directory - A
publicdirectory exists - The
RAILPACK_STATIC_FILE_ROOTenvironment variable is set
Root Directory Resolution
Section titled “Root Directory Resolution”The provider determines the root directory in this order:
RAILPACK_STATIC_FILE_ROOTenvironment variable if setrootdirectory specified inStaticfileif presentpublicdirectory if it exists- Current directory (
.) ifindex.htmlexists in root
Configuration
Section titled “Configuration”Staticfile
Section titled “Staticfile”You can configure static file serving with a Staticfile in your project
root:
# root directory to serveroot: dist
# enable SPA routing: fall back to index.html for unmatched routesindex_fallback: trueindex_fallback defaults to false. Enable it for single-page applications
(React, Vue, Angular, etc.) where the frontend router handles all routes and
the server should always serve index.html for unmatched paths.
Config Variables
Section titled “Config Variables”| Variable | Description | Example |
|---|---|---|
RAILPACK_STATIC_FILE_ROOT | Override the root directory | public |
Custom Caddyfile
Section titled “Custom Caddyfile”Railpack uses a custom Caddyfile that is used to serve the static files. You can overwrite this file with your own Caddyfile at the root of your project.