Skip to main content
Module

x/fast/mod.ts>middleware.CorsOptions

Small web framework with near-native performance.
Go to Latest
interface middleware.CorsOptions
import { type middleware } from "https://deno.land/x/fast@4.0.0-alpha.3/mod.ts";
const { CorsOptions } = middleware;

An Object will all possible options that can be passed to cors. The default options are:

{
 origin: '*',
 methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
 preflightContinue: false,
 optionsSuccessStatus: 204,
}

https://github.com/danteissaias/fast#cors-configurations

Properties

optional
origin: StaticOrigin | OriginFn

The value to match against the Access-Control-Allow-Origin header in the requestuest. Defaults to '*'.

It can be a boolean, string, a regular expression, an array of those, or a function that returns one of those.

If set to '*' all origins will be allowed.

If set to true then Access-Control-Allow-Origin will reflect the origin of the requestuest.

If set to false then all origins will be denied (Access-Control-Allow-Origin will not be set).

If set to a regular expression then the requestuest origin will be matched against it.

If set to a function, it will receive the requestuest origin string as the first parameter and the requestuest as the second parameter. It can return a promise.

optional
methods: string | string[]

Customizes the Access-Control-Allow-Methods header.

It can be a string or an array of strings. Defaults to 'GET,HEAD,PUT,PATCH,POST,DELETE'.

optional
allowedHeaders: string | string[]

Configures the Access-Control-Allow-Headers header.

It can be a string or an array of strings. There's no default value (the header is omitted).

optional
exposedHeaders: string | string[]

Configures the Access-Control-Expose-Headers header.

It can be a string or an array of strings. There's no default value (the header is omitted).

optional
credentials: boolean

Configures the Access-Control-Allow-Credentials header.

It can be a boolean. But the header is only set if it is true. There's no default value (the header is omitted).

optional
maxAge: number

Configures the Access-Control-Max-Age header.

Its value has to be an integer. There's no default value (the header is omitted).