HTTP API server package for Scramjet Transform Hub. It provides router construction, HTTP/HTTPS server setup, REST/operation/stream handler registration, forwarding controllers, middleware helpers, and routed-forwarding utilities used by Host, Manager, and MultiManager API surfaces.
- Factory façade:
src/index.tsexportsgetRouter()andcreateServer()as the primary construction APIs, plus handler, strategy, middleware, and type exports. - Sequential router adapter:
src/lib/0http.tsand route handler modules wrap0http/router behavior behindAPIRouteandAPIServercontracts. - Handler factory pattern:
src/handlers/get.ts,crud.ts,op.ts, andstream.tscreate route registration functions for request/response and stream-oriented endpoints.src/handlers/forward.tsandrouted-forward.tsprovide HTTP forwarding and verser2-backed streaming forward. - Strategy pattern:
src/strategies/round-robin.tsandconsistent-hash.tsprovide pluggable target selection for forwarding. - Defensive middleware wrapping:
safeHandler()andsafeDecorator()catch middleware/decorator errors and preserve router error handling. - Server config:
src/config/ServerConfiguration.tsvalidates SSL/key/cert paths for HTTPS setup. - CORS/OPTIONS: Built-in
corsMiddlewareandoptionsMiddlewareinsrc/middlewares/. - No-jitless AVA mode: Tests use
SCRAMJET_AVA_JITLESS=0to opt out of jitless AVA child process mode.
- Consumers call
getRouter()for an in-memory route surface orcreateServer(conf)for an HTTP/HTTPS server-backed API surface. - Handler factories register endpoint callbacks on the sequential router; stream handlers map duplex/upstream/downstream APIs onto Node streams.
- Incoming requests pass through global decorators/middleware, route lookup, and handler-specific parsing/extraction helpers from
src/lib/. - Forwarding paths use either URL-based forwarding controllers or
forwardRoutedRequest()to stream a request body through an injected routed transport and pipe the routed response back to the client. - Server request completion writes structured log records to a
scramjetDataStream, which auto-resumes until a consumer reads it.
- Consumed by
packages/host, Manager/instance API code, and tests that need a local API server/router abstraction. - Depends on
@scramjet/typesroute/server contracts,@scramjet/obj-logger,@scramjet/symbols,@scramjet/utility,0http, andscramjetstreams. - Verser2 rollout additions use
src/handlers/routed-forward.tsfor streaming broker-backed HTTP forwarding (forwardRoutedRequest(),normalizeForwardedHeaders()). - Package-level AVA tests under
test/cover server behavior, REST/stream methods, forwarding, and routed-forward semantics. - API v2 route registration uses
@scramjet/api-router'sregisterHttpRoutes()instead of direct handler factories, though the api-server surfaces remain the target.