Fotone
GitHub

Fotone The fastest one-command static web server in the world.

One command. All the power.

npx fotone ./dist --port 8080
Listening on http://0.0.0.0:8080
Benchmark metric
Benchmark workload

Requests per second

  • Fotone134,890
  • Express33,211
  • Fastify26,397
  • Hono20,444
Apple M3 · 100 concurrent connections · Pipeline 10 · 5s per run

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 8080

Docker

Save the Dockerfile in an empty directory. Create the example site, build the image, and run it. Open http://localhost:8080.

Dockerfile
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 8080
mkdir -p dist
echo 'Hello, world!' > dist/index.html
docker build -t fotone-test .
docker run --rm -p 8080:8080 fotone-test

CLI 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.

OptionsDefaultDescription
--host <host>0.0.0.0Bind address. Uses HOST when this option is omitted.
--port <port>0Bind TCP port. Uses PORT when this option is omitted. Port 0 lets the OS choose.
--spa[=<file>]offEnable SPA fallback. Bare --spa uses index.html.
--langs <tags>noneRedirect / by browser language. Use comma-separated tags with the default first, such as en,it,fr.
--rewrite <pattern>=<replacement>noneRewrite matching URLs to local paths. Repeatable.
--redirect <source>=<target>[=<status>]noneRedirect matching URLs. Repeatable. Status defaults to 302.
-H, --header <name:value>noneAdd a response header. Repeatable.
--auth <user:password|htpasswd>noneEnable Basic Auth with a password or an Apache bcrypt record.
--auth-include <path-or-glob>noneProtect only matching paths with Basic Auth. Repeatable.
--auth-exclude <path-or-glob>noneExclude matching paths from Basic Auth. Repeatable.
--corsoffSet Access-Control-Allow-Origin.
--coopoffSet Cross-Origin-Opener-Policy.
--coepoffSet Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy.
--pnaoffSet Access-Control-Allow-Private-Network.
-i, --immutableoffSet the Cache-Control to immutable.
-m, --maxage <seconds>noneSet the Cache-Control max-age in seconds.
-t, --timeout <seconds>30Set the idle timeout in seconds. Use 0 to disable it.
--env-json <names>noneExpose a comma-separated list of environment variables as JSON at /env.
-q, --quietoffSuppress output and logs.
-c, --config <file>noneLoad a JSON configuration file.
-h, --helpoffShow help and exit.
-v, --versionoffShow 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
OptionTypeDefaultDescription
basePathstring"/"Public URL prefix for static files. Start with / and omit the trailing slash except for /. The health endpoint stays at /health.
trustedProxiesstring[][]IPv4 or IPv6 addresses and CIDR ranges. Fotone uses X-Forwarded-For to determine the client IP only if the direct peer is trusted.
extensionFallbackbooleantrueTry the .html file when an extensionless path has no exact file.
cleanUrlsbooleantrueRedirect requests for existing .html files to URLs without the extension.
stripTrailingSlashbooleantrueRedirect paths with a trailing slash to the path without it. Keep the slash on /.
spaExcludesstring[][]Public path patterns that skip SPA fallback. Applies when --spa is enabled.
headersobject[][]Set or remove response headers for matching public paths.
rewritesobject[][]Serve a local path under the static root without changing the browser URL.
redirectsobject[][]Send the browser to a local path or an absolute HTTP or HTTPS URL.
languageRedirectobjectoffRedirect requests for / based on Accept-Language. Use --langs to override these destinations. Explicit redirects take precedence.

Rule fields

OptionTypeDefaultDescription
headers[].pathsstring[]RequiredOne or more public path patterns. Apply the rule once if any pattern matches.
headers[].<name>string or nullOptionalUse 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[].sourcestringRequiredPublic path pattern to match.
rewrites[].destinationstringRequiredLocal path starting with /, relative to the static root.
redirects[].sourcestringRequiredPublic path pattern to match.
redirects[].destinationstringRequiredLocal path starting with / or an absolute HTTP or HTTPS URL.
redirects[].statusnumber302Allowed status codes are 301, 302, 303, 307, and 308.
languageRedirect.defaultstringRequiredLocal path to use when no configured language matches.
languageRedirect.<tag>stringOptionalUse 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
    }
  ]
}