Fotone The fastest one-command static web server in the world.
One command. All the power.
npx fotone ./dist --port 8080Requests per second
- Fotone134,890
- Express33,211
- Fastify26,397
- Hono20,444
Linux ARM64 Docker example
0.00 MB
Peak req/s vs Express
0.0×
Less peak RAM than Express (4 KiB)
0%
Why Fotone
Fotone is a minimal static web server written in Rust. It runs without Node.js. In our benchmarks, Fotone outperformed every static web server from npm that we tested.
Fotone can redirect visitors from / to a language your site supports based on their browser preferences. It serves precompressed Brotli and gzip assets and supports SPA fallback, cache headers, COOP and COEP headers.
If your app needs different settings in staging and production, Fotone can expose selected environment variables to the browser at runtime, so you can use the same image in both.
Features
Serve a directory with one command
Run npx fotone ./dist --port 8080. File changes take effect without a restart.
Support single-page web applications
Serve index.html or a custom fallback for deep links. Exclude paths from the fallback as needed.
Serve precompressed assets
Select Brotli or gzip files from your build based on the client’s Accept-Encoding header.
Control browser caching
Use ETag and Last-Modified to return 304 Not Modified for unchanged assets. Set max-age and immutable.
Configure rewrites and redirects
Set clean HTML URLs, a URL base path, and a custom 404.html. Apply response headers globally or by path, with shortcuts for CORS and cross-origin isolation.
Run behind an HTTPS reverse proxy
Serve HTTP/1.1 and cleartext HTTP/2 (h2c) on the same port. Log client IPs through configured trusted proxies.
Protect with Basic Auth
Use a username and password or an Apache bcrypt record. Include or exclude paths by pattern.
Expose selected .env values at runtime
Serve selected variables to the browser as JSON at /env, such as a public API URL.
Cache small files and stream larger ones
Keep small files in a bounded memory cache and stream larger files from disk.
Quick start
Use Node.js 24 or later. Pass your build directory and add flags for the behavior your site needs.
npx fotone ./dist --port 8080Docker
Save the Dockerfile in an empty directory. Create the example site, build the image, and run it. Open http://localhost:8080.
FROM node:26-alpine AS build
WORKDIR /build
RUN npm install fotone
RUN cp "node_modules/fotone/bin/fotone-linux-$(node -p process.arch)" /usr/local/bin/fotone
FROM alpine
COPY --from=build /usr/local/bin/fotone /usr/local/bin/fotone
COPY dist/ /srv/
CMD exec /usr/local/bin/fotone /srv --port 8080mkdir -p dist
echo 'Hello, world!' > dist/index.html
docker build -t fotone-test .
docker run --rm -p 8080:8080 fotone-testCLI Reference
npx fotone <root> [options]Fotone serves index.html at directory URLs when that file exists. Use --spa to serve a fallback page for unmatched routes.
| Options | Default | Description |
|---|---|---|
--host <host> | 0.0.0.0 | Bind address. Uses HOST when this option is omitted. |
--port <port> | 0 | Bind TCP port. Uses PORT when this option is omitted. Port 0 lets the OS choose. |
--spa[=<file>] | off | Enable SPA fallback. Bare --spa uses index.html. |
--langs <tags> | none | Redirect / by browser language. Use comma-separated tags with the default first, such as en,it,fr. |
--rewrite <pattern>=<replacement> | none | Rewrite matching URLs to local paths. Repeatable. |
--redirect <source>=<target>[=<status>] | none | Redirect matching URLs. Repeatable. Status defaults to 302. |
-H, --header <name:value> | none | Add a response header. Repeatable. |
--auth <user:password|htpasswd> | none | Enable Basic Auth with a password or an Apache bcrypt record. |
--auth-include <path-or-glob> | none | Protect only matching paths with Basic Auth. Repeatable. |
--auth-exclude <path-or-glob> | none | Exclude matching paths from Basic Auth. Repeatable. |
--cors | off | Set Access-Control-Allow-Origin. |
--coop | off | Set Cross-Origin-Opener-Policy. |
--coep | off | Set Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy. |
--pna | off | Set Access-Control-Allow-Private-Network. |
-i, --immutable | off | Set the Cache-Control to immutable. |
-m, --maxage <seconds> | none | Set the Cache-Control max-age in seconds. |
-t, --timeout <seconds> | 30 | Set the idle timeout in seconds. Use 0 to disable it. |
--env-json <names> | none | Expose a comma-separated list of environment variables as JSON at /env. |
-q, --quiet | off | Suppress output and logs. |
-c, --config <file> | none | Load a JSON configuration file. |
-h, --help | off | Show help and exit. |
-v, --version | off | Show the version and exit. |
Config Reference
Pass a JSON file with --config. All top-level keys are optional. Fotone rejects unknown keys.
npx fotone ./dist --config fotone.json| Option | Type | Default | Description |
|---|---|---|---|
basePath | string | "/" | Public URL prefix for static files. Start with / and omit the trailing slash except for /. The health endpoint stays at /health. |
trustedProxies | string[] | [] | IPv4 or IPv6 addresses and CIDR ranges. Fotone uses X-Forwarded-For to determine the client IP only if the direct peer is trusted. |
extensionFallback | boolean | true | Try the .html file when an extensionless path has no exact file. |
cleanUrls | boolean | true | Redirect requests for existing .html files to URLs without the extension. |
stripTrailingSlash | boolean | true | Redirect paths with a trailing slash to the path without it. Keep the slash on /. |
spaExcludes | string[] | [] | Public path patterns that skip SPA fallback. Applies when --spa is enabled. |
headers | object[] | [] | Set or remove response headers for matching public paths. |
rewrites | object[] | [] | Serve a local path under the static root without changing the browser URL. |
redirects | object[] | [] | Send the browser to a local path or an absolute HTTP or HTTPS URL. |
languageRedirect | object | off | Redirect requests for / based on Accept-Language. Use --langs to override these destinations. Explicit redirects take precedence. |
Rule fields
| Option | Type | Default | Description |
|---|---|---|---|
headers[].paths | string[] | Required | One or more public path patterns. Apply the rule once if any pattern matches. |
headers[].<name> | string or null | Optional | Use the header name as the key. Set a string value or use null to remove a value set earlier. Fotone reserves framing and encoding headers. |
rewrites[].source | string | Required | Public path pattern to match. |
rewrites[].destination | string | Required | Local path starting with /, relative to the static root. |
redirects[].source | string | Required | Public path pattern to match. |
redirects[].destination | string | Required | Local path starting with / or an absolute HTTP or HTTPS URL. |
redirects[].status | number | 302 | Allowed status codes are 301, 302, 303, 307, and 308. |
languageRedirect.default | string | Required | Local path to use when no configured language matches. |
languageRedirect.<tag> | string | Optional | Use a lowercase language tag as the key and a local path as its value. The redirect keeps the original query string. |
Rules match public paths using exact paths, globs such as /assets/**, or named segments such as /users/:id. A final :path* captures zero or more segments. Use :path in the rewrite or redirect destination to insert the captured value.
Redirects run before rewrites. For each rule type, the first match wins. Fotone checks CLI rules before JSON rules. Header rules run in file order after generated headers and CLI headers.
{
"languageRedirect": {
"default": "/en/home",
"en": "/en/home",
"it": "/it/benvenuto"
},
"headers": [
{
"paths": [
"/assets/**"
],
"Cache-Control": "public, max-age=86400"
}
],
"redirects": [
{
"source": "/old/:path*",
"destination": "/guide/:path",
"status": 301
}
]
}