Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as middleware from "https://raw.githubusercontent.com/worker-tools/middleware/master/index.ts";

§Classes

EffectsList

§Variables

ALLOW_CREDENTIALS
ALLOW_HEADERS
ALLOW_METHODS
ALLOW_ORIGIN
anyCORS

A CORS middleware that gives clients exactly the permissions they ask for, unless constrained by the definitions in options.

basics
BINARY

Standard MIME type for binary data

bodyParser
caching
cors

A CORS middleware that gives clients exactly the permissions they ask for, unless constrained by the definitions in options.

defaultBodyParser
encryptedCookies
flushed
FORM
FORM_DATA
JSON
ORIGIN
plainCookies
REQUEST_HEADERS
REQUEST_METHOD
signedCookies
strictCORS

A CORS middleware that only grants the permissions defined via options.

TEXT_HTML
TEXT_PLAIN
unsignedCookies
VARY
X_BINARY

Non-standard MIME type for binary data. Sometimes used, so included anyway.

§Functions

accepts

Determines if a request body content type is acceptable to this endpoint.

acceptsEncodings

Determines if a request body content encoding is acceptable to this endpoint.

acceptsLanguages

Determines if a request body content language is acceptable to this endpoint.

combine

Type-enforcing left-to-right function composition function. The first parameter can be a function of any arity, but the remaining parameters must be unary functions. The return type of one function must be compatible with the argument of next function in the argument list (i.e. types flow from left-to-right)

contentEncodings

Performs content negotiation over the content encoding of the response.

contentLanguages

Performs content negotiation over the content language of the response.

contentTypes

Performs content negotiation over the content type of the response.

cookieSession

Cookie session middleware for worker runtimes.

cookiesFrom
createMiddleware

A helper function to create user-defined middleware.

executeEffects deprecated
provides

Performs content negotiation over the content type of the response.

providesEncodings

Performs content negotiation over the content encoding of the response.

providesLanguages

Performs content negotiation over the content language of the response.

storageSession

Session middleware for worker runtimes.

withMiddleware deprecated

Takes a handler function of the form (x: Request, ctx: Context) => Awaitable<Response> and applies middleware to it.

§Interfaces

Accepted
AcceptedEncoding
AcceptedLanguage
BasicsContext
BodyBinaryContext
BodyFormContext
BodyFormDataContext
BodyJSONContext
BodyParserOptions
BodyTextContext
BodyVendorJSONContext
ContentEncoding
ContentLanguage
ContentType
Context
CookiesContext
CookieSessionContext
CookieSessionOptions
CookiesOptions
CORSOptions
EncryptedCookiesContext
ExtendableEvent

Extends the lifetime of the install and activate events dispatched on the global scope as part of the service worker lifecycle. This ensures that any functional events (like FetchEvent) are not dispatched until it upgrades database schemas and deletes the outdated cache entries.

ExtendableEventInit
FetchEvent

This is the event type for fetch events dispatched on the service worker global scope. It contains information about the fetch, including the request and how the receiver will treat the response. It provides the event.respondWith() method, which allows us to provide a response to this fetch.

FetchEventInit
FlushedContext
SignedCookiesContext
StorageSessionContext
StorageSessionOptions
UnsignedCookiesContext
URLPatternComponentResult
URLPatternInit
URLPatternResult

§Type Aliases

BodyContext
BodyParsable
BodyParserDeps
CacheOptions

The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and shared caches (e.g. Proxies, CDNs).

ContextOf

Helper type to get the context type of a given middleware function.

Cookies

An object of the cookies sent with this request. It is for reading convenience only. To make changes, use the associated cookie store instead (provided by the middleware along with this object)

ErrorContext deprecated
ErrorHandler deprecated
Handler deprecated
Method
Middleware deprecated
Rec

Any record of unknown values

ResponseEffect
StrictCORSOptions
URLPatternInput