Skip to main content
This release is 6 versions behind 17.1.3 — the latest version of @oak/oak. Jump to latest

@oak/oak@16.0.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
8 months ago (16.0.0)
interface ProxyOptions

Options which can be specified on the proxy middleware.

Type Parameters

R extends string
S extends State = Record<string, any>

Properties

optional
fetch: Fetch

The fetch function to use to proxy the request. This defaults to the global fetch function. It will always be called with a second argument which contains an object of { context } which the context property will be an instance of RouterContext.

This is designed for mocking purposes or implementing a fetch() callback that needs access the current context when it is called.

optional
headers:
HeadersInit
| ProxyHeadersFunction<S>
| ProxyRouterHeadersFunction<R, P, S>

Additional headers that should be set in the response. The value can be a headers init value or a function that returns or resolves with a headers init value.

optional
map: Record<string, R> | ProxyMapFunction<R, P>

Either a record or a proxy map function that will allow proxied requests being handled by the middleware to be remapped to a different remote path.

optional
match:
string
| RegExp
| ProxyMatchFunction<R, P, S>

A string, regular expression or proxy match function what determines if the proxy middleware should proxy the request.

If the value is a string the match will be true if the requests pathname starts with the string. In the case of a regular expression, if the pathname

A flag that indicates if traditional proxy headers should be set in the response. This defaults to true.

Methods

optional
contentType(
url: string,
contentType?: string,
):
Promise<string | undefined>
| string
| undefined

A callback hook that is called after the response is received which allows the response content type to be adjusted. This is for situations where the content type provided by the proxy server might not be suitable for responding with.

A callback hook which will be called before each proxied fetch request to allow the native Request to be modified or replaced.

A callback hook which will be called after each proxied fetch response is received to allow the native Response to be modified or replaced.

Add Package

deno add jsr:@oak/oak

Import symbol

import { type ProxyOptions } from "@oak/oak";

---- OR ----

Import directly with a jsr specifier

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

Add Package

npx jsr add @oak/oak

Import symbol

import { type ProxyOptions } from "@oak/oak";

Add Package

yarn dlx jsr add @oak/oak

Import symbol

import { type ProxyOptions } from "@oak/oak";

Add Package

pnpm dlx jsr add @oak/oak

Import symbol

import { type ProxyOptions } from "@oak/oak";

Add Package

bunx jsr add @oak/oak

Import symbol

import { type ProxyOptions } from "@oak/oak";