locagate
v1.0.1
Published
Tiny, file-configurable local API gateway — YAML config, prefix routing, optional JWT. Run with one command.
Downloads
166
Readme
locagate
Tiny, file-configurable local API gateway. YAML config, prefix path routing, optional JWT. One command, zero setup.
npx locagate ./config.yaml
pnpm dlx locagate ./config.yamlUsage
Create a locagate.yaml:
listen: "0.0.0.0:5000"
jwt:
enabled: true
secret: "$JWT_SECRET"
passthrough: false
routes:
- match: "/v1/core/*"
target: "http://localhost:3000"
- match: "/*"
target: "http://localhost:3003"Run it:
npx locagate ./locagate.yamlOr install globally:
npm install -g locagate
locagate ./locagate.yamlConfiguration reference
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| listen | string | "0.0.0.0:5000" | Address + port to bind |
| jwt.enabled | bool | false | Enable JWT verification |
| jwt.secret | string | — | HMAC secret ($VAR / ${VAR:-default} expands env vars) |
| jwt.passthrough | bool | false | Allow unauthenticated requests through |
| jwt.exclude | string[] | [] | Path prefixes that skip JWT |
| routes | array | — | Route table (first match wins) |
Environment variable expansion works in jwt.secret and route target fields.
Route matching
| Pattern | Matches |
|---------|---------|
| /* | All paths (catch-all) |
| /v1/core/* | /v1/core/... and /v1/core |
| /health | Only /health |
How it works
- Reads your YAML config (first argument, or
./locagate.yaml) - Expands
$VAR/${VAR:-default}from environment variables - For each incoming request, walks the route table top-to-bottom
- First match wins — proxies to
targetvia Node'shttp.request - WebSocket upgrade requests (e.g., Next.js HMR) are proxied transparently
- JWT verification via HS256,
x-gateway-userheader injected on success
Files
bin/locagate.js — CLI entrypoint (what npx runs)
src/index.ts — HTTP server, routing, proxying, JWT check
src/config.ts — YAML/JSON config loading with $VAR expansion
src/router.ts — prefix-based route matching
src/jwt.ts — HS256 JWT verification
locagate.yaml.sample — annotated example config