Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@koa/cors

Package Overview
Dependencies
Maintainers
8
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koa/cors - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

10

History.md
3.1.0 / 2020-05-17
==================
**features**
* [[`013662a`](http://github.com/koajs/cors/commit/013662ae1ab65c4af230c17dfa1044609502b15b)] - feat: add support for using a function to determine whether or not to allow credentials. (#68) (mcohen75 <<mcohen75@gmail.com>>)
**others**
* [[`da84dec`](http://github.com/koajs/cors/commit/da84dec7fa16af95d157a549bd473e7bfa4aa152)] - docs: update install script (dead-horse <<dead_horse@qq.com>>)
* [[`eba3b44`](http://github.com/koajs/cors/commit/eba3b446055bd14b86d19dfc81d8ed5f83a8a534)] - chore: ES6 Object spread (#66) (Alpha <<AlphaWong@users.noreply.github.com>>)
3.0.0 / 2019-03-11

@@ -3,0 +13,0 @@ ==================

25

index.js

@@ -24,3 +24,6 @@ 'use strict';

options = Object.assign({}, defaults, options);
options = {
...defaults,
...options,
};

@@ -43,3 +46,2 @@ if (Array.isArray(options.exposeHeaders)) {

options.credentials = !!options.credentials;
options.keepHeadersOnError = options.keepHeadersOnError === undefined || !!options.keepHeadersOnError;

@@ -67,2 +69,10 @@

let credentials;
if (typeof options.credentials === 'function') {
credentials = options.credentials(ctx);
if (credentials instanceof Promise) credentials = await credentials;
} else {
credentials = !!options.credentials;
}
const headersSet = {};

@@ -79,3 +89,3 @@

if (options.credentials === true) {
if (credentials === true) {
set('Access-Control-Allow-Credentials', 'true');

@@ -98,4 +108,7 @@ }

err.headers = Object.assign({}, errHeadersSet, headersSet, { vary: varyWithOrigin });
err.headers = {
...errHeadersSet,
...headersSet,
...{ vary: varyWithOrigin },
};
throw err;

@@ -116,3 +129,3 @@ }

if (options.credentials === true) {
if (credentials === true) {
ctx.set('Access-Control-Allow-Credentials', 'true');

@@ -119,0 +132,0 @@ }

{
"name": "@koa/cors",
"version": "3.0.0",
"version": "3.1.0",
"description": "Cross-Origin Resource Sharing(CORS) for koa",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,3 +26,3 @@ @koa/cors

```bash
$ npm install @koa/cors@2 --save
$ npm install @koa/cors --save
```

@@ -57,3 +57,3 @@

* - {String|Number} maxAge `Access-Control-Max-Age` in seconds
* - {Boolean} credentials `Access-Control-Allow-Credentials`
* - {Boolean|Function(ctx)} credentials `Access-Control-Allow-Credentials`, default is false.
* - {Boolean} keepHeadersOnError Add set headers to `err.header` if an error is thrown

@@ -60,0 +60,0 @@ * @return {Function} cors middleware

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc