Static Files

Serving Static Files

By default, Foal serves static files from the public/ directory.

Example

public/

index.html
styles.css
app.js

Paths served

/ -> returns index.html
/index.html -> returns index.html
/styles.css -> returns styles.css
/app.js -> returns app.js

Change the directory

You can change the directory where the static files are served using the configuration key staticPath.

Example with config/default.json

{
"settings": {
"staticPath": "another-directory/"
}
}

Note: In previous versions of FoalTS (<v1.0.0), this parameter was badly named staticUrl.

Add a virtual prefix path

You can add a virtual prefix path using the configuration key staticPathPrefix.

Example with config/default.json

{
"settings": {
"staticPathPrefix": "static/"
}
}

Paths served (example)

/static/ -> returns index.html
/static/index.html -> returns index.html
/static/styles.css -> returns styles.css
/static/app.js -> returns app.js