Static File Hosting
The FileHandler serves static files from a configured root directory. This is the most common use case for hosting websites.
Configuration
A static site is defined in config.yml with the dir: key:
sites:
- domain: "example.com"
dir: "site/main-site"
The folder path is relative to plugins/ZyveraWeb/. The above example serves files from plugins/ZyveraWeb/site/main-site/.
File Resolution
When a request arrives, the handler resolves files in this order:
-
Directory → index.html — If the path maps to a directory,
index.htmlinside that directory is served. -
Extension-less → .html — If no file is found and the path has no extension,
.htmlis appended. For example,/aboutbecomes/about.html. -
Exact match — If the file exists as-is, it is served directly.
Path Traversal Protection
The handler prevents directory traversal attacks by:
- Resolving the requested path relative to the web root.
- Normalizing the result (removing
..and.segments). - Verifying the resolved path still starts with the web root.
If a traversal attempt is detected, the server returns HTTP 403 Forbidden.
MIME Types
The handler maps file extensions to Content-Type headers:
| Extension | Content-Type |
|---|---|
.html |
text/html |
.css |
text/css |
.js |
application/javascript |
.json |
application/json |
.png |
image/png |
.jpg, .jpeg |
image/jpeg |
.gif |
image/gif |
.svg |
image/svg+xml |
.txt |
text/plain |
.ico |
image/x-icon |
| Other | application/octet-stream |
Example
plugins/ZyveraWeb/site/main-site/:
index.html
about.html
css/style.css
js/app.js
images/logo.png
| URL | Serves |
|---|---|
/ |
index.html |
/about |
about.html |
/css/style.css |
css/style.css |
/js/app.js |
js/app.js |
/images/logo.png |
images/logo.png |
/nonexistent |
404 Not Found |
No comments to display
No comments to display