API server runtime surface for request routing, middleware wrapping, forwarding, and HTTP/HTTPS server setup.
- Central factory module that re-exports router/server helpers and strategy implementations.
- Wraps middleware/decorators with error guards to protect the router pipeline.
- Builds the server from a config object, preferring injected server instances before creating HTTP/HTTPS servers.
- Handler registrations:
getRouter()andcreateServer()return objects withget,op,crud,duplex,upstream,downstream,use,decorate,forwardmethods. - Stream-based logging: server request completion logs to a
DataStreamthat pauses only when explicitly accessed. - Exports
forwardRoutedRequestandnormalizeForwardedHeadersfromsrc/handlers/routed-forwardfor verser2-backed streaming forwarding.
getRouter()creates a sequential router and wires GET/CRUD/op/stream handlers plus forwarding via handler factories inhandlers/.createServer()constructs the router/server pair, installs error/default handlers, then logs request completion.- Logging is buffered through a
DataStreamthat pauses when.logis first accessed.
| Directory | Responsibility |
|---|---|
config/ |
Server configuration validation (SSL, ports) |
handlers/ |
Route handler factories: GET, CRUD, operation, stream, forward, routed-forward |
lib/ |
0http router wrapper, definitions, duplex stream helper, data extractors, mime helpers |
middlewares/ |
CORS, OPTIONS pre-flight middleware |
strategies/ |
Forwarding strategies: round-robin, consistent-hash |
types/ |
TypeScript interfaces for API server contracts (ServerConfig) |
- Uses
@scramjet/typesfor API route/server contracts and parser types. - Uses
scramjetDataStreamfor request logging. - Integrates with local handlers, stream middleware, and forwarding strategies.
forwardRoutedRequest/normalizeForwardedHeadersexported for verser2 routed-forward use by Host/Manager.- Consumed by Host, Manager, and MultiManager for their HTTP API surfaces.