# @starefossen/express-cors

> Cross-origin resource sharing headers middleware for Express.js

Latest version **1.1.2** (published 2016-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @starefossen/express-cors
pnpm add @starefossen/express-cors
yarn add @starefossen/express-cors
bun add @starefossen/express-cors
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2016-08-13 |
| First published | 2016-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Hans Kristian Flaatten |
| Maintainers | starefossen |
| Keywords | ES6, cors, express, headers, middleware, security |

## Links

- npm: https://www.npmjs.com/package/@starefossen/express-cors
- Repository: https://github.com/Starefossen/node-express-cors
- Homepage: https://github.com/Starefossen/node-express-cors#readme
- Issues: https://github.com/Starefossen/node-express-cors/issues
- npm.io page: https://npm.io/package/@starefossen/express-cors

## Dependencies (1)

- [@starefossen/http-error](https://npm.io/package/@starefossen/http-error.md) ^1.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2016-08-13
- 1.1.1 — 2016-07-04
- 1.1.0 — 2016-06-17
- 1.0.0 — 2016-06-02

## README

# @starefossen/express-cors

[![Build status](https://app.wercker.com/status/82a3fcc4a07532a3dff7f71c17996d1a/s "wercker status")](https://app.wercker.com/project/bykey/82a3fcc4a07532a3dff7f71c17996d1a)
[![Codacy grade](https://img.shields.io/codacy/grade/2a40f5c2df884985872e4d0a0c9ce60b.svg "Codacy")](https://www.codacy.com/app/starefossen/node-express-cors)
[![Codacy coverage](https://img.shields.io/codacy/coverage/2a40f5c2df884985872e4d0a0c9ce60b.svg "Codacy")](https://www.codacy.com/app/starefossen/node-express-cors)
[![NPM downloads](https://img.shields.io/npm/dm/@starefossen/express-cors.svg "NPM downloads")](https://www.npmjs.com/package/@starefossen/express-cors)
[![NPM version](https://img.shields.io/npm/v/@starefossen/express-cors.svg "NPM version")](https://www.npmjs.com/package/@starefossen/express-cors)
[![Node version](https://img.shields.io/node/v/@starefossen/express-cors.svg "Node version")](https://www.npmjs.com/package/@starefossen/express-cors)
[![Dependency status](https://img.shields.io/david/Starefossen/node-express-cors.svg "Dependency status")](https://david-dm.org/Starefossen/node-express-cors)

Smart CORS headers middleware for your Express.js applications.

## Install

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

## Usage

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

### Simple

The simple configuration is controlled by environment variables:

| Variable | Description | Default |
|----------|-------------|---------|
| `CORS_ALLOW_CREDENTIALS` | allow-credentials (boolean) | `undefined` |
| `CORS_ALLOW_HEADERS` | allow-headers header (comma separated string) | `Content-Type` |
| `CORS_ALLOW_METHODS` | allow-methods header (comma separated string) | `GET, OPTIONS` |
| `CORS_ALLOW_ORIGINS` | orins whitelist (comma seperated string) | `""` |
| `CORS_DENY_ORIGINS` | origins blacklist (comma seperated string) | `""` |
| `CORS_EXPOSE_HEADERS` | expose-headers header (comma seperated string) | `""` |
| `CORS_MAX_AGE` | max-age header (integer) | `0` |
| `CORS_REQUIRE_ORIGIN` | require origin header from client (boolean) | `false` |

```js
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.

```js
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](https://github.com/Starefossen/node-express-cors/blob/master/LICENSE)

---
_Source: https://npm.io/package/@starefossen/express-cors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
