Skip to content

@webframe/core ​

The server, its router, the middleware chain, the request and response classes, and workers. It has no dependencies.

sh
npm install @webframe/core

Exports ​

Functions ​

NameWhat it does
defineServer(options)Makes a server for your routes. See The server.
defineMiddleware(middlewares)Makes a route from a chain of middleware, the first 30 typed. See Middleware.
defineWorker(options)Makes a worker that runs jobs from a source. See Workers.
defineIntervalSource(schedule), defineMemorySource()The job sources that come with core: a timer, and a queue in memory.
createRequestHandler({ routes, logger })The router defineServer uses, for attaching to a Node server of your own. Its routes is a Map.
parseRequestUrl(target)Parses a request's URL. A path starting // stays a path, where new URL would read it as another host.
isHttpMethod(value), isArrayOfHttpMethods(value), isAllowedMethod(value, methods)Type guards for HTTP methods, in capitals.

Classes ​

NameWhat it is
ContextualIncomingMessageThe request. See Reading the request.
ContextualServerResponseThe response. See Sending a response.
WorkerStoppingError, UnknownJobErrorWhy a worker refused a job: it's stopping, or the job's name has no handler.

Values ​

NameWhat it is
defaultLoggerThe console, without debug lines. Used when a server isn't given a logger.
silentLoggerDrops everything. Useful in tests.
httpMethodsThe nine HTTP methods.
DEFAULT_BODY_LIMITThe largest body read by default: 1 MiB.
TYPED_CHAIN_LENGTHHow many middleware in a chain are typed: 30.

Types ​

NameWhat it is
Middleware<Input, Output>A step in a chain: given Input, it adds what Output has beyond it. Output defaults to Input.
ServiceRequestContextWhat every chain starts with: incomingMessage, serverResponse, logger.
RouteHandlerWhat a route is: (context) => void | Promise<void>.
Routes, ServerOptions, ServerdefineServer's routes, options and result.
LoggerAnything with debug, info, warn and error.
HtmlWhat the HTML send methods take: a string, a promise of one, or a readable stream.
HttpMethod'GET' | 'POST' | …
ReadBodyOptions{ limit?: number }, for the body readers.
Job, JobHandler, JobContext, JobSource, SourceControls, WorkerHealth, WorkerOptions, Worker, MemorySource, IntervalScheduleThe worker's types. See Workers.
NewPropertiesOnly<A, B>, DeepPartial<T>The helper types the chain is built from.

Released under the MIT Licence.