|
4 | 4 |
|
5 | 5 | # spa-to-http |
6 | 6 |
|
7 | | -> World's fastest lightweight zero-configuration SPA HTTP server. |
| 7 | +> A zero-configuration HTTP server for built SPA bundles. |
8 | 8 |
|
9 | | -Serve a built SPA bundle over HTTP with sensible defaults for caching and optional Brotli/Gzip compression. It’s designed to run cleanly in Docker and behind reverse proxies like Traefik or Cloudflare. |
| 9 | +`spa-to-http` serves your built frontend (`dist/`) with SPA fallback routing, cache-friendly defaults, and optional Brotli/Gzip compression. |
10 | 10 |
|
11 | | -## Quick Start |
| 11 | +If you want to ship a static SPA quickly in Docker without writing Nginx config, this is the fast path. |
| 12 | + |
| 13 | +## Why use spa-to-http |
| 14 | + |
| 15 | +- Fast-to-deploy: run one container, mount your build folder, done. |
| 16 | +- Operationally simple: no custom web-server config files. |
| 17 | +- Lightweight runtime: small Docker image and fast startup. |
| 18 | +- SPA-focused defaults: sensible handling for `index.html`, hashed assets, and optional compression. |
| 19 | + |
| 20 | +## Benchmark Highlights |
| 21 | + |
| 22 | +From [`docs/benchmarks.md`](docs/benchmarks.md): |
| 23 | + |
| 24 | +- Startup readiness (100 startups): `1.358s` vs Nginx `1.514s` (`11.5%` faster) |
| 25 | +- Small-file throughput (0.5 KiB HTML): `80,497 req/s` vs `79,214 req/s` |
| 26 | +- Mid-size JS throughput (5 KiB): `66,126 req/s` vs `62,831 req/s` (`5.2%` faster) |
| 27 | +- Docker image size comparison in docs: `13.2 MiB` (`spa-to-http`) vs `142 MiB` (Nginx sample image) |
| 28 | + |
| 29 | +See full comparison table and source methodology in [`docs/benchmarks.md`](docs/benchmarks.md). |
| 30 | + |
| 31 | +## Get Started in 60 Seconds |
12 | 32 |
|
13 | 33 | ```bash |
14 | 34 | # Serve ./dist at http://localhost:8080 |
15 | 35 | docker run --rm -p 8080:8080 -v $(pwd)/dist:/code devforth/spa-to-http:latest |
16 | 36 | ``` |
17 | 37 |
|
18 | | -For local (non-Docker) runs, see [Local Run (Console)](docs/getting-started.md#local-run-console). |
| 38 | +Open `http://localhost:8080`. |
19 | 39 |
|
20 | | -## Key Features |
| 40 | +## Recommended: Build SPA + Runtime in One Dockerfile |
21 | 41 |
|
22 | | -- Zero-configuration Docker setup for common SPA outputs |
23 | | -- Small image and fast startup (Go binary) |
24 | | -- Optional Brotli/Gzip compression |
25 | | -- Cache-control optimized for hashed assets and index.html |
26 | | -- Works with popular SPA toolchains (React, Vue, Angular, Svelte, Vite, Webpack) |
| 42 | +In most cases, users prefer building the SPA and serving it in one image: |
| 43 | + |
| 44 | +```dockerfile |
| 45 | +FROM node:20-alpine AS builder |
| 46 | +WORKDIR /code |
| 47 | +COPY package*.json ./ |
| 48 | +RUN npm ci |
| 49 | +COPY . . |
| 50 | +RUN npm run build |
| 51 | + |
| 52 | +FROM devforth/spa-to-http:latest |
| 53 | +COPY --from=builder /code/dist/ . |
| 54 | +``` |
27 | 55 |
|
28 | | -## Example |
| 56 | +Build and run: |
29 | 57 |
|
30 | 58 | ```bash |
31 | | -# Enable Brotli and serve on a custom port |
32 | | -docker run --rm -p 8082:8082 -v $(pwd)/dist:/code devforth/spa-to-http:latest --brotli --port 8082 |
| 59 | +docker build -t my-spa . |
| 60 | +docker run --rm -p 8080:8080 my-spa |
33 | 61 | ``` |
34 | 62 |
|
35 | | ---- |
| 63 | +## Common Copy-Paste Commands |
36 | 64 |
|
37 | | -## Documentation |
| 65 | +### Custom port + Brotli |
38 | 66 |
|
39 | | -| Guide | Description | |
40 | | -|-------|-------------| |
41 | | -| [Getting Started](docs/getting-started.md) | Install, build, and run | |
42 | | -| [Configuration](docs/configuration.md) | Environment variables and CLI flags | |
43 | | -| [Deployment](docs/deployment.md) | Docker and reverse proxy setup | |
44 | | -| [Architecture](docs/architecture.md) | Project structure and request flow | |
45 | | -| [Benchmarks](docs/benchmarks.md) | spa-to-http vs Nginx | |
| 67 | +```bash |
| 68 | +docker run --rm -p 8082:8082 \ |
| 69 | + -v $(pwd)/dist:/code \ |
| 70 | + devforth/spa-to-http:latest \ |
| 71 | + --brotli --port 8082 |
| 72 | +``` |
| 73 | + |
| 74 | +### Basic Auth (Docker) |
| 75 | + |
| 76 | +```bash |
| 77 | +docker run --rm -p 8080:8080 \ |
| 78 | + -e BASIC_AUTH="admin:secret" \ |
| 79 | + -e BASIC_AUTH_REALM="SPA Server" \ |
| 80 | + -v $(pwd)/dist:/code \ |
| 81 | + devforth/spa-to-http:latest |
| 82 | +``` |
| 83 | + |
| 84 | +### Compose / reverse proxy setup |
| 85 | + |
| 86 | +For full Docker Compose and Traefik examples, see [`docs/deployment.md`](docs/deployment.md). |
| 87 | + |
| 88 | +## Feature Snapshot |
| 89 | + |
| 90 | +- Zero-configuration Docker usage for SPA bundles |
| 91 | +- Optional Brotli/Gzip compression |
| 92 | +- Cache-control tuning (`--cache-max-age`, `--ignore-cache-control-paths`) |
| 93 | +- SPA mode toggle (`--spa` / `SPA_MODE`) |
| 94 | +- In-memory file cache (`--cache`, `--cache-buffer`) |
| 95 | +- Optional request logging and basic auth |
| 96 | + |
| 97 | +## Documentation Map |
| 98 | + |
| 99 | +| Need | Go to | |
| 100 | +|---|---| |
| 101 | +| Fast Docker onboarding | [`docs/getting-started.md`](docs/getting-started.md) | |
| 102 | +| Local development and source-based workflows | [`docs/development.md`](docs/development.md) | |
| 103 | +| Full flag/env reference and examples | [`docs/configuration.md`](docs/configuration.md) | |
| 104 | +| Deployment behind Traefik / reverse proxy | [`docs/deployment.md`](docs/deployment.md) | |
| 105 | +| Internal package layout and request flow | [`docs/architecture.md`](docs/architecture.md) | |
| 106 | +| Detailed benchmark tables and source link | [`docs/benchmarks.md`](docs/benchmarks.md) | |
46 | 107 |
|
47 | 108 | ## License |
48 | 109 |
|
|
0 commit comments