The core kernel functionality for Raptor.
Classes
An error used primarily in 400 bad request errors.
The Bun server implementation for Raptor.
- serve(): voidhandler: RequestHandler,options?: { port?: number; hostname?: string; }
Start the server with the given request handler.
- toConnInfo(): ConnInfo | undefinedserver: BunServerHandle,request: Request
Read the connection for a request from Bun's server handle.
An error used primarily in 409 conflict request errors.
- status: number
The HTTP status code associated with the error.
HTTP content type negotiation service.
- getBaseMediaType(contentType: string): string
Extract base media type without parameters.
- getTypeSpecificity(type: string): number
Calculate specificity score for a media type.
- isAcceptable(): booleanrequest: Request,contentType: string
Check if a content-type is acceptable based on the accept header.
- isJsonType(contentType: string): boolean
Check if a content type is JSON or JSON-based.
- negotiate(request: Request): string
Detect the most appropriate content type for a request based on headers.
- parseAcceptHeader(header: string): string[]
Parse Accept header and return types sorted by quality value and specificity.
The context definition.
- _hasContentType: boolean
If the response has content type set.
- connection: ConnInfo
The connection the request arrived on, where the adapter supplied one.
- error: HttpError | Error
An error caught by the system.
- hasContentType(): boolean
Check if the response has a content-type set.
- request: Request
The current HTTP request.
- response: Response
The current HTTP response.
The response manager takes the response body and processes it into a valid HTTP response.
- getTypeKey(body: any): string
Determine the type key for a given body.
- process(): Promise<Response>body: any,context: Context
Process a body into a valid Response object.
- processors: Map<string, ResponseProcessor>
All available response processors.
- register(): voidtype: string,processor: ResponseProcessor
Add a new processor to the response manager.
- strictContentNegotiation: boolean
Whether strict content negotiation is enabled.
The Deno server implementation for Raptor.
- serve(): voidhandler: RequestHandler,options?: { port?: number; hostname?: string; }
Start the server with the given request handler.
- toConnInfo(info?: DenoServeHandlerInfo): ConnInfo | undefined
Read the connection from Deno's request info.
The plain text processor for HTTP responses.
- escapeHtml(text: string): string
Escape HTML special characters to prevent XSS.
- generateBasicHtmlBody(error: Error & { errors?: Record<string, string[]>; }): string
Generate a basic HTML body for the error.
- generateErrorsList(errors?: Record<string, string[]>): string
Generate the validation errors list if present.
- generateHtmlContent(error: Error & { errors?: Record<string, string[]>; }): string
Generate the main content body.
- generateHtmlHead(title: string): string
Generate the HTML head section.
- generateHtmlStyles(): string
Generate the CSS styles for the error page.
- isHttpError(error: Error): error is HttpError
Check if it's an HTTP Error.
- process(): Responsebody: any,context: Context
Handle the response and process plain text if found.
- transformResponse(): Responseerror: Error,context: Context
Transform the response based on request content type and accept headers.
An error used primarily in 403 forbidden request errors.
- status: number
The HTTP status code associated with the error.
An error used primarily in 410 gone request errors.
- status: number
The HTTP status code associated with the error.
The root initialiser for the framework.
- add(middleware: Middleware): this
Add new middleware to the container.
- catch(handler: ErrorHandler): this
Add custom error handling middleware.
- config: Config
Config which can be used to change kernel functionality.
- errorHandler: ErrorHandler | null
An optional custom error handler function.
- executeMiddleware(): Promise<Response | void>context: Context,index: number
Execute a chosen middleware by index.
- getConfig(): Config
Get the configured kernel config.
- getResponseManager(): ResponseManager
Get the currently registered response manager.
- getServerManager(): ServerManager
Get the currently registered server manager.
- initialiseDefaultConfig(): Config
Initialises the default kernel config.
- internalErrorHandler(context: Context): Promise<void>
Handle the uncaught error internally.
- listen(): void
Alias method for "serve".
- middleware: Middleware[]
The available middleware.
- next(context: Context): Promise<void>
Handle the processing of middleware.
- processMiddlewareResponse(): Promise<void>body: unknown,context: Context
Process an unknown response body with HTTP context.
- processUncaughtError(context: Context): Promise<void>
Process an uncaught error with HTTP context.
- registerConfigMiddleware(config: Config): void
Register middleware defined in config.
- registerConfigResponseProcessors(config: Config): void
Register response processors defined in config.
- respond(): Promise<Response>request: Request,connection?: ConnInfo
Handle an HTTP request and respond.
- responseManager: ResponseManager
The response manager for the kernel.
- serve(): void
Serve the application.
- serverManager: ServerManager
The server manager for the kernel.
- setResponseManager(manager: ResponseManager): this
Set or override the response manager for the kernel.
- setServerManager(manager: ServerManager): this
Set or override the server manager for the kernel.
- use(middleware: Middleware): this
Alias method for "add".
- adapters: Map<string, ServerAdapter>No documentation available
- getServerAdapter(): string
Detect the runtime and return correct adapter.
- register(): voidname: string,adapter: ServerAdapter
Register a new adapter to the server manager.
- serve(): voidhandler: RequestHandler,options?: { port?: number; hostname?: string; }
Start the server with the given request handler.
An error used primarily in 405 method not allowed request errors.
- status: number
The HTTP status code associated with the error.
The Node server implementation for Raptor.
- authorityFor(options?: { port?: number; hostname?: string; }): string
Build the authority to fall back to when a request carries no usable
Hostheader. - fromWebResponse(): Promise<void>response: Response,nodeResponse: NodeServerResponse
Convert from web response.
- hostFor(): stringnodeRequest: NodeIncomingMessage,authority: string
Read the request authority from the
Hostheader. - serve(): Promise<void>handler: RequestHandler,options?: { port?: number; hostname?: string; }
Start the server with the given request handler.
- toConnInfo(nodeRequest: NodeIncomingMessage): ConnInfo | undefined
Read the connection from the node socket.
- toWebRequest(): RequestnodeRequest: NodeIncomingMessage,authority: string
Convert to web request.
An error used primarily in 406 not acceptable request errors.
- status: number
The HTTP status code associated with the error.
An error used primarily in 404 not found request errors.
- status: number
The HTTP status code associated with the error.
The object processor for HTTP responses.
- process(): Responsebody: any,context: Context
Handle the response and process objects if found.
An error used primarily in 408 request timeout errors.
- status: number
The HTTP status code associated with the error.
The Response processor for HTTP responses.
- process(): Responseresponse: any,_context: Context
Handle the response and process if found.
An error used primarily in 500 server errors.
- status: number
The HTTP status code associated with the error.
The HTML processor for HTTP responses.
- process(): Responsebody: any,context: Context
Handle the response and process HTML if found.
An error used primarily in 418 gone request errors.
- status: number
The HTTP status code associated with the error.
An error used primarily in 429 gone request errors.
- status: number
The HTTP status code associated with the error.
An error used primarily in 422 unprocessable entity request errors.
Functions
Canonicalise an IP address into one stable text form.
Resolve the address of the client that made this request.
Compile a trust policy, validating it up front.
Build connection details from a runtime-reported peer address.
Interfaces
Config which can be used to change kernel functionality.
- errorHandler: ErrorHandler | null
The custom error handler for catching and responding to system errors.
- hostname: string
The hostname the kernel will use to serve the appliation.
- middleware: Middleware[]
Middleware stack, providing a way to add middleware to the kernel.
- port: number
The port the kernel will use to serve the application.
- response: { manager?: ResponseManager; processors?: Record<string, ResponseProcessor>; }
Response configuration, providing a way to override the kernel's response management.
- server: { manager?: ServerManager; }
Server configuration, providing a way to override the kernel's server management.
- strictContentNegotiation: boolean
Enable strict RFC 7231 content negotiation.
Manages the processing of response bodies into HTTP Response objects.
An HTTP response body processor.
- process(): Promise<Response> | Responsebody: any,context: Context
Handle the response body and process.
- serve(): void | Promise<void>handler: RequestHandler,options?: { port?: number; hostname?: string; }
Start the server with the given request handler.
Manages the serving of applications.
Type Aliases
The request handler a server adapter drives. connection is optional, as not
every runtime exposes one.
How far to trust X-Forwarded-For when resolving a client address.
Decides whether the hop at index in the chain may be trusted.
Variables
A convenient helper for dealing with response body types.