@marblejs/middleware-cors
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

Middleware CORS

A CORS middleware for Marble.js.

Usage

Example to allow incoming requests.

import { cors$ } from '@marblejs/middleware-cors';

const middlewares = [
  logger$,
  cors$({
    origin: '*',
    methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
    optionsSuccessStatus: 204,
    allowHeaders: '*',
    maxAge: 3600,
  })
];

const effects = [
  endpoint1$,
  endpoint2$,
  ...
];

const app = httpListener({ middlewares, effects });

Available options

To configure CORS middleware you can follow this interface.

interface CORSOptions {
  origin?: string | string[] | RegExp;
  methods?: HttpMethod[];
  optionsSuccessStatus?: HttpStatus;
  allowHeaders?: string | string[];
  exposeHeaders?: string[];
  withCredentials?: boolean;
  maxAge?: number;
}

License: MIT

Package Sidebar

Install

npm i @marblejs/middleware-cors

Weekly Downloads

70

Version

4.1.0

License

MIT

Unpacked Size

17.3 kB

Total Files

33

Last publish

Collaborators

  • jflakus