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 2.2.3 to 3.0.0

6

History.md
3.0.0 / 2019-03-11
==================
**others**
* [[`369d31d`](http://github.com/koajs/cors/commit/369d31db7835ed344011706f9506d45a44638017)] - refactor: use async function, support options.origin return promise (#59) (Yiyu He <<dead_horse@qq.com>>)
2.2.3 / 2018-12-19

@@ -3,0 +9,0 @@ ==================

25

index.js

@@ -45,3 +45,3 @@ 'use strict';

return function cors(ctx, next) {
return async function cors(ctx, next) {
// If the Origin header is not present terminate this set of steps.

@@ -55,14 +55,9 @@ // The request is outside the scope of this specification.

if (!requestOrigin) {
return next();
}
if (!requestOrigin) return await next();
let origin;
if (typeof options.origin === 'function') {
// FIXME: origin can be promise
origin = options.origin(ctx);
if (!origin) {
return next();
}
if (origin instanceof Promise) origin = await origin;
if (!origin) return await next();
} else {

@@ -92,5 +87,7 @@ origin = options.origin || requestOrigin;

if (!options.keepHeadersOnError) {
return next();
return await next();
}
return next().catch(err => {
try {
return await next();
} catch (err) {
const errHeadersSet = err.headers || {};

@@ -100,6 +97,6 @@ const varyWithOrigin = vary.append(errHeadersSet.vary || errHeadersSet.Vary || '', 'Origin');

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

@@ -113,3 +110,3 @@ // Preflight Request

// this not preflight request, ignore it
return next();
return await next();
}

@@ -116,0 +113,0 @@

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

@@ -21,4 +21,4 @@ "main": "index.js",

"autod": "*",
"eslint": "^2.3.0",
"eslint-config-egg": "^2.0.0",
"eslint": "^5.15.1",
"eslint-config-egg": "^7.1.0",
"istanbul": "*",

@@ -46,3 +46,3 @@ "koa": "^2.5.1",

"engines": {
"node": ">= 6.0.0"
"node": ">= 8.0.0"
},

@@ -49,0 +49,0 @@ "author": "fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)",

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