alepha@docs:~/docs/framework/packages/alepha/server$
cat core.md | pretty2 min read
Last commit:
#Alepha - Server
#Installation
Part of the alepha package. Import from alepha/server.
npm install alepha
#Overview
Convention-driven HTTP server with automatic validation and type inference.
Features:
- Type-safe API endpoints with schema validation
- Lower-level HTTP route definitions
- Automatic request/response validation via Zod
- Convention-based URL generation (
/api/{ActionName}) - Direct invocation (
run()) or HTTP (fetch()) - Built-in authentication integration
- Multipart file upload handling
- Response compression (gzip, brotli, zstd)
- Security headers (HSTS, CSP, X-Frame-Options, etc.)
- Content-type auto-negotiation (JSON, form-data, text)
- HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
- Error handling: BadRequestError, ValidationError, ForbiddenError, UnauthorizedError, ConflictError, NotFoundError
#API Reference
#Primitives
$action- Creates a server action primitive for defining type-safe HTTP endpoints.$circuit- Middleware that implements the circuit breaker pattern.$middleware- Applies middleware functions to every route whose path starts with a prefix.$route- Create a basic endpoint.$sse- Creates a Server-Sent Events (SSE) primitive for streaming typed events to clients.
#Providers
ServerHealthProvider- RegistersGET /healthandGET /healthz.ServerHelmetProvider- Provides a configurable way to apply essential HTTP security headersServerMultipartProvider- Parsesmultipart/form-datarequest bodies into route handler input.ServerNotReadyProvider- On every request, this provider checks if the server is ready.ServerProvider- Base server provider to handle incoming requests and route them.ServerRouterProvider- Main router for all routes server side.
#Environment Variables
Environment variables used to configure this module. These can be set in your .env file or through your deployment configuration.
| Variable | Type | Default | Description |
|---|---|---|---|
SERVER_HOST |
text | localhost | Set 0.0.0.0 to listen on all interfaces. |
SERVER_PORT |
integer | 3000 | Set 0 to listen on a random port. |
TRUST_PROXY |
boolean | true | Trust proxy headers for client IP |
TRUST_PROXY_HOPS |
integer | 1 | Number of trusted reverse proxies in front of this server |