Comparing version 2.2.3 to 3.0.0
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)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10610
0
107