1.1.1 • Published 2 months ago

@elysiajs/cors v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@elysiajs/cors

Plugin for elysia that for Cross Origin Requests (CORs)

Installation

bun add @elysiajs/cors

Example

import { Elysia } from 'elysia'
import { cors } from '@elysiajs/cors'

const app = new Elysia()
    .use(cors())
    .listen(8080)

Config

origin

@default true

Assign the Access-Control-Allow-Origin header.

Value can be one of the following:

  • string - String of origin which will directly assign to Access-Control-Allow-Origin

  • boolean - If set to true, Access-Control-Allow-Origin will be set to * (accept all origin)

  • RegExp - Pattern to use to test with request's url, will accept origin if matched.

  • Function - Custom logic to validate origin acceptance or not. will accept origin if true is returned.

    • Function will accepts Context just like Handler

      // Example usage
      app.use(cors, {
          origin: ({ request, headers }) => true
      })
      
      // Type Definition
      type CORSOriginFn = (context: Context) => boolean | void
  • Array<string | RegExp | Function> - Will try to find truthy value of all options above. Will accept Request if one is true.

methods

@default *

Assign Access-Control-Allow-Methods header.

Value can be one of the following: Accept:

  • undefined | null | '' - Ignore all methods.

  • * - Accept all methods.

  • HTTPMethod - Will be directly set to Access-Control-Allow-Methods.

    • Expects either a single method or a comma-delimited string (eg: 'GET, PUT, POST')
  • HTTPMethod[] - Allow multiple HTTP methods.

allowedHeaders

@default *

Assign Access-Control-Allow-Headers header.

Allow incoming request with the specified headers.

Value can be one of the following:

  • string

    • Expects either a single method or a comma-delimited string (eg: 'Content-Type, Authorization').
  • string[] - Allow multiple HTTP methods.

exposedHeaders

@default *

Assign Access-Control-Exposed-Headers header.

Return the specified headers to request in CORS mode.

Value can be one of the following:

  • string

    • Expects either a single method or a comma-delimited string (eg: 'Content-Type, 'X-Powered-By').
  • string[] - Allow multiple HTTP methods.

credentials

@default true

Assign Access-Control-Allow-Credentials header.

Allow incoming requests to send credentials header.

  • boolean - Available if set to true.

maxAge

@default 5

Assign Access-Control-Max-Age header.

Allow incoming requests to send credentials header.

  • number - Duration in seconds to indicates how long the results of a preflight request can be cached.

preflight

@default true

Add [OPTIONS] /* handler to handle preflight request which response with HTTP 204 and CORS hints.

  • boolean - Available if set to true.
1.1.1

2 months ago

1.1.0

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.1.0-exp.1

4 months ago

1.1.0-exp.0

4 months ago

1.1.0-rc.1

4 months ago

1.1.0-rc.0

4 months ago

1.0.2

8 months ago

1.0.0

8 months ago

1.0.0-rc.1

8 months ago

1.0.0-rc.2

8 months ago

1.0.0-rc.0

9 months ago

1.0.0-beta.2

9 months ago

1.0.0-beta.1

9 months ago

1.0.0-beta.0

9 months ago

0.8.0

11 months ago

0.8.0-rc.1

11 months ago

0.8.0-rc.0

11 months ago

0.7.0-beta.0

1 year ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.0-rc.0

1 year ago

0.6.0

1 year ago

0.3.0

2 years ago

0.3.0-beta.0

2 years ago

0.5.0

2 years ago

0.5.2

1 year ago

0.5.0-rc.0

2 years ago

0.5.1

1 year ago

0.1.0

2 years ago

0.1.0-rc.6

2 years ago

0.1.0-rc.5

2 years ago

0.1.0-rc.4

2 years ago

0.1.0-rc.3

2 years ago

0.1.0-rc.2

2 years ago