Skip to content

Commit 19ca7cf

Browse files
committed
docs: update README.md
1 parent 801e704 commit 19ca7cf

File tree

7 files changed

+191
-114
lines changed

7 files changed

+191
-114
lines changed

README.md

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,106 @@
44

55
# spa-to-http
66

7-
> World's fastest lightweight zero-configuration SPA HTTP server.
7+
> A zero-configuration HTTP server for built SPA bundles.
88
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.
1010

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
1232

1333
```bash
1434
# Serve ./dist at http://localhost:8080
1535
docker run --rm -p 8080:8080 -v $(pwd)/dist:/code devforth/spa-to-http:latest
1636
```
1737

18-
For local (non-Docker) runs, see [Local Run (Console)](docs/getting-started.md#local-run-console).
38+
Open `http://localhost:8080`.
1939

20-
## Key Features
40+
## Recommended: Build SPA + Runtime in One Dockerfile
2141

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+
```
2755

28-
## Example
56+
Build and run:
2957

3058
```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
3361
```
3462

35-
---
63+
## Common Copy-Paste Commands
3664

37-
## Documentation
65+
### Custom port + Brotli
3866

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) |
46107

47108
## License
48109

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[← Deployment](deployment.md) · [Back to README](../README.md) · [Benchmarks →](benchmarks.md)
1+
[← Deployment](deployment.md) · [Development](development.md) · [Back to README](../README.md) · [Benchmarks →](benchmarks.md)
22

33
# Architecture
44

docs/benchmarks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
|---|---|---|
99
| Zero-configuration | ✅ No config files, SPA serving works out of the box | ❌ Requires dedicated config file |
1010
| Config via env/CLI | ✅ Yes | ❌ No |
11-
| Docker image size |13.2 MiB (v1.0.3) | ❌ 142 MiB (v1.23.1) |
11+
| Docker image size |7.54 MiB (v1.1.1) | ❌ 142 MiB (v1.23.1) |
1212
| Brotli out-of-the-box | ✅ Yes | ❌ Requires module |
1313

14-
Performance numbers from the benchmark section of this post:
14+
Performance numbers and benchmark setup details are from:
1515
`https://devforth.io/blog/deploy-react-vue-angular-in-docker-simply-and-efficiently-using-spa-to-http-and-traefik/`
1616

1717
| | spa-to-http | Nginx |

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[← Getting Started](getting-started.md) · [Back to README](../README.md) · [Deployment →](deployment.md)
1+
[← Getting Started](getting-started.md) · [Development](development.md) · [Back to README](../README.md) · [Deployment →](deployment.md)
22

33
# Configuration
44

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[← Configuration](configuration.md) · [Back to README](../README.md) · [Architecture →](architecture.md)
1+
[← Configuration](configuration.md) · [Development](development.md) · [Back to README](../README.md) · [Architecture →](architecture.md)
22

33
# Deployment
44

docs/development.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[← Getting Started](getting-started.md) · [Back to README](../README.md) · [Configuration →](configuration.md)
2+
3+
# Development
4+
5+
This page is for contributors and local source-based workflows.
6+
7+
## Prerequisites
8+
9+
- Go 1.24+
10+
- Git
11+
12+
## Run from Source
13+
14+
Build and run the server directly:
15+
16+
```bash
17+
cd src
18+
go build -o spa-to-http
19+
./spa-to-http --directory ../test/frontend/dist
20+
```
21+
22+
Or run without building a binary:
23+
24+
```bash
25+
cd src
26+
go run . --directory ../test/frontend/dist
27+
```
28+
29+
Open `http://localhost:8080` in your browser.
30+
31+
## Configure via CLI Flags
32+
33+
```bash
34+
cd src
35+
go run . \
36+
--directory ../test/frontend/dist \
37+
--brotli \
38+
--gzip \
39+
--spa=true \
40+
--logger \
41+
--log-pretty \
42+
--cache-max-age 3600 \
43+
--threshold 2048
44+
```
45+
46+
## Configure via Environment Variables
47+
48+
```bash
49+
cd src
50+
ADDRESS=0.0.0.0 PORT=8080 \
51+
GZIP=true BROTLI=true \
52+
SPA_MODE=true LOGGER=true LOG_PRETTY=true \
53+
CACHE_MAX_AGE=3600 THRESHOLD=2048 \
54+
DIRECTORY=../test/frontend/dist \
55+
go run .
56+
```
57+
58+
## Basic Auth (Console)
59+
60+
```bash
61+
cd src
62+
go run . \
63+
--directory ../test/frontend/dist \
64+
--basic-auth "admin:secret" \
65+
--basic-auth-realm "SPA Server"
66+
```
67+
68+
## Test with `test/frontend/dist`
69+
70+
Use the built-in fixture to verify routing, caching, and compression behavior.
71+
72+
### Console
73+
74+
```bash
75+
cd src
76+
go run . --directory ../test/frontend/dist
77+
```
78+
79+
### Docker
80+
81+
```bash
82+
docker run --rm -p 8080:8080 -v $(pwd)/test/frontend/dist:/code devforth/spa-to-http:latest
83+
```
84+
85+
Open `http://localhost:8080` in your browser.
86+
87+
## See Also
88+
89+
- [Getting Started](getting-started.md) — Fast Docker onboarding
90+
- [Configuration](configuration.md) — Full options reference
91+
- [Architecture](architecture.md) — Package structure and request flow

docs/getting-started.md

Lines changed: 12 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,13 @@
1-
[Back to README](../README.md) · [Configuration](configuration.md)
1+
[Back to README](../README.md) · [Development](development.md)
22

33
# Getting Started
44

55
## Prerequisites
66

7-
- Docker (recommended)
7+
- Docker
88
- A built SPA bundle (for example, `dist/` from Vite, Webpack, or similar)
99

10-
## Local Run (Console)
11-
12-
Build from source and run the server directly:
13-
14-
```bash
15-
cd src
16-
go build -o spa-to-http
17-
./spa-to-http --directory ../test/frontend/dist
18-
```
19-
20-
Or run without building a binary:
21-
22-
```bash
23-
cd src
24-
go run . --directory ../test/frontend/dist
25-
```
26-
27-
Open `http://localhost:8080` in your browser.
28-
29-
### Configure via CLI Flags
30-
31-
```bash
32-
cd src
33-
go run . \
34-
--directory ../test/frontend/dist \
35-
--brotli \
36-
--gzip \
37-
--spa=true \
38-
--logger \
39-
--log-pretty \
40-
--cache-max-age 3600 \
41-
--threshold 2048
42-
```
43-
44-
### Configure via Environment Variables
45-
46-
```bash
47-
cd src
48-
ADDRESS=0.0.0.0 PORT=8080 \
49-
GZIP=true BROTLI=true \
50-
SPA_MODE=true LOGGER=true LOG_PRETTY=true \
51-
CACHE_MAX_AGE=3600 THRESHOLD=2048 \
52-
DIRECTORY=../test/frontend/dist \
53-
go run .
54-
```
55-
56-
### Basic Auth (Console)
57-
58-
```bash
59-
cd src
60-
go run . \
61-
--directory ../test/frontend/dist \
62-
--basic-auth "admin:secret" \
63-
--basic-auth-realm "SPA Server"
64-
```
65-
66-
Full list of options is in [Configuration](configuration.md).
67-
68-
## Serve a Local Build (Docker)
10+
## Run a Local Build (Docker)
6911

7012
```bash
7113
# Serve ./dist at http://localhost:8080
@@ -74,7 +16,7 @@ docker run --rm -p 8080:8080 -v $(pwd)/dist:/code devforth/spa-to-http:latest
7416

7517
Open `http://localhost:8080` in your browser.
7618

77-
### Basic Auth (Docker)
19+
## Basic Auth (Docker)
7820

7921
```bash
8022
docker run --rm -p 8080:8080 \
@@ -89,12 +31,11 @@ docker run --rm -p 8080:8080 \
8931
Use this pattern when you want to build the SPA and ship a small runtime image:
9032

9133
```dockerfile
92-
FROM node:20-alpine as builder
93-
WORKDIR /code/
94-
ADD package-lock.json .
95-
ADD package.json .
34+
FROM node:20-alpine AS builder
35+
WORKDIR /code
36+
COPY package*.json ./
9637
RUN npm ci
97-
ADD . .
38+
COPY . .
9839
RUN npm run build
9940

10041
FROM devforth/spa-to-http:latest
@@ -104,35 +45,19 @@ COPY --from=builder /code/dist/ .
10445
Build and run:
10546

10647
```bash
107-
docker build -q . | xargs docker run --rm -p 8080:8080
108-
```
109-
110-
## Test With `test/frontend/dist`
111-
112-
Use the built-in fixture to verify routing, caching, and compression behavior.
113-
114-
### Console
115-
116-
```bash
117-
cd src
118-
go run . --directory ../test/frontend/dist
48+
docker build -t my-spa .
49+
docker run --rm -p 8080:8080 my-spa
11950
```
12051

121-
### Docker
122-
123-
```bash
124-
docker run --rm -p 8080:8080 -v $(pwd)/test/frontend/dist:/code devforth/spa-to-http:latest
125-
```
126-
127-
Open `http://localhost:8080` in your browser.
128-
12952
## Next Steps
13053

13154
- Configure compression, cache settings, and ports in [Configuration](configuration.md)
13255
- Deploy behind Traefik or another reverse proxy in [Deployment](deployment.md)
56+
- For source-based local runs and contributor workflow, see [Development](development.md)
13357

13458
## See Also
13559

60+
- [Development](development.md) — Local setup, source runs, and fixture usage
13661
- [Configuration](configuration.md) — Environment variables and CLI flags
13762
- [Deployment](deployment.md) — Docker and reverse proxy setup
13863
- [Architecture](architecture.md) — Project structure and request flow

0 commit comments

Comments
 (0)