Skip to main content

@oak/oak@17.1.0
Built and signed on GitHub Actions

A middleware framework for handling HTTP with Deno, Node.js, Bun and Cloudflare Workers 🐿️🦕🥟⚙️

This package works with Cloudflare Workers, Node.js, Deno, Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
a week ago (17.1.0)
interface ApplicationOptions

Available options that are used when creating a new instance of Application.

Type Parameters

S extends State
R extends ServerRequest

Properties

optional
contextState:
"clone"
| "prototype"
| "alias"
| "empty"

Determine how when creating a new context, the state from the application should be applied. A value of "clone" will set the state as a clone of the app state. Any non-cloneable or non-enumerable properties will not be copied. A value of "prototype" means that the application's state will be used as the prototype of the the context's state, meaning shallow properties on the context's state will not be reflected in the application's state. A value of "alias" means that application's .state and the context's .state will be a reference to the same object. A value of "empty" will initialize the context's .state with an empty object.

The default value is "clone".

optional
jsonBodyReplacer: (
key: string,
value: unknown,
context: Context<S>,
) => unknown

An optional replacer function to be used when serializing a JSON response. The replacer will be used with JSON.stringify() to encode any response bodies that need to be converted before sending the response.

This is intended to allow responses to contain bigints and circular references and encoding other values which JSON does not support directly.

This can be used in conjunction with jsonBodyReviver to handle decoding of request bodies if the same semantics are used for client requests.

If more detailed or conditional usage is required, then serialization should be implemented directly in middleware.

optional
jsonBodyReviver: (
key: string,
value: unknown,
context: Context<S>,
) => unknown

An optional reviver function to be used when parsing a JSON request. The reviver will be used with JSON.parse() to decode any response bodies that are being converted as JSON.

This is intended to allow requests to deserialize to bigints, circular references, or other values which JSON does not support directly.

This can be used in conjunction with jsonBodyReplacer to handle decoding of response bodies if the same semantics are used for responses.

If more detailed or conditional usage is required, then deserialization should be implemented directly in the middleware.

optional
keys: KeyStack | Key[]

An initial set of keys (or instance of KeyStack) to be used for signing cookies produced by the application.

If true, any errors handled by the application will be logged to the stderr. If false nothing will be logged. The default is true.

All errors are available as events on the application of type "error" and can be accessed for custom logging/application management via adding an event listener to the application:

const app = new Application({ logErrors: false });
app.addEventListener("error", (evt) => {
  // evt.error will contain what error was thrown
});
optional
proxy: boolean

If set to true, proxy headers will be trusted when processing requests. This defaults to false.

optional
serverConstructor: ServerConstructor<R>

A server constructor to use instead of the default server for receiving requests.

Generally this is only used for testing.

optional
state: S

The initial state object for the application, of which the type can be used to infer the type of the state for both the application and any of the application's context.

Add Package

deno add jsr:@oak/oak

Import symbol

import { type ApplicationOptions } from "@oak/oak/application";

---- OR ----

Import directly with a jsr specifier

import { type ApplicationOptions } from "jsr:@oak/oak/application";

Add Package

npx jsr add @oak/oak

Import symbol

import { type ApplicationOptions } from "@oak/oak/application";

Add Package

yarn dlx jsr add @oak/oak

Import symbol

import { type ApplicationOptions } from "@oak/oak/application";

Add Package

pnpm dlx jsr add @oak/oak

Import symbol

import { type ApplicationOptions } from "@oak/oak/application";

Add Package

bunx jsr add @oak/oak

Import symbol

import { type ApplicationOptions } from "@oak/oak/application";