🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@starefossen/express-cors

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@starefossen/express-cors

Cross-origin resource sharing headers middleware for Express.js

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

@starefossen/express-cors

Build status Codacy grade Codacy coverage NPM downloads NPM version Node version Dependency status

Smart CORS headers middleware for your Express.js applications.

Install

$ npm install @starefossen/express-cors --save

Usage

const cors = require('@starefossen/express-cors');

Simple

The simple configuration is controlled by environment variables:

VariableDescriptionDefault
CORS_ALLOW_CREDENTIALSallow-credentials (boolean)undefined
CORS_ALLOW_HEADERSallow-headers header (comma separated string)Content-Type
CORS_ALLOW_METHODSallow-methods header (comma separated string)GET, OPTIONS
CORS_ALLOW_ORIGINSorins whitelist (comma seperated string)""
CORS_DENY_ORIGINSorigins blacklist (comma seperated string)""
CORS_EXPOSE_HEADERSexpose-headers header (comma seperated string)""
CORS_MAX_AGEmax-age header (integer)0
CORS_REQUIRE_ORIGINrequire origin header from client (boolean)false
const cors = require('@starefossen/express-cors');

app.use(cors.middleware);

Advanced

The advanced configuration takes in a configuration object. All values defaults to their environment conunterpart as statated in the simple configuration.

const cors = require('@starefossen/express-cors');

app.use(cors({
  allowCredentials: false,
  allowHeaders: 'Content-Type',
  allowMethods: 'GET, OPTIONS',
  allowOrigins: 'foo.com,bar.com',
  denyOrigins: 'example.com',
  exposeHeaders: 'x-request-time',
  maxAge: 133734,
  requireOrigin: true,
});

Localhost

If you want to allow local development domains like localhost or file:// you can add the following to your CORS_ALLOW_ORIGINS environment variable:

CORS_ALLOW_ORIGINS='localhost,null'

MIT Licensed

Keywords

ES6

FAQs

Package last updated on 13 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts