@tinyhttp/cors
Advanced tools
Comparing version 0.2.6 to 0.2.7
# @tinyhttp/cors | ||
## 0.2.7 | ||
### Patch Changes | ||
- Compress whitespace | ||
## 0.2.6 | ||
@@ -4,0 +10,0 @@ |
@@ -1,35 +0,2 @@ | ||
import {vary}from'es-vary';/** | ||
* CORS Middleware | ||
*/ | ||
const cors = ({ origin = '*', methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'], allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus = 204, }) => { | ||
return (req, res, next) => { | ||
// Checking the type of the origin property | ||
if (typeof origin === 'boolean' && origin === true) | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
else if (typeof origin === 'string') | ||
res.setHeader('Access-Control-Allow-Origin', origin); | ||
else if (typeof origin === 'function') | ||
res.setHeader('Access-Control-Allow-Origin', origin(req, res)); | ||
if ((typeof origin === 'string' && origin !== '*') || typeof origin === 'function') | ||
vary(res, 'Origin'); | ||
// Setting the Access-Control-Allow-Methods header from the methods array | ||
res.setHeader('Access-Control-Allow-Methods', methods.join(', ').toUpperCase()); | ||
// Setting the Access-Control-Allow-Headers header | ||
if (allowedHeaders) | ||
res.setHeader('Access-Control-Allow-Headers', allowedHeaders); | ||
// Setting the Access-Control-Expose-Headers header | ||
if (exposedHeaders) | ||
res.setHeader('Access-Control-Expose-Headers', exposedHeaders); | ||
// Setting the Access-Control-Allow-Credentials header | ||
if (credentials) | ||
res.setHeader('Access-Control-Allow-Credentials', 'true'); | ||
// Setting the Access-Control-Max-Age header | ||
if (maxAge) | ||
res.setHeader('Access-Control-Max-Age', maxAge); | ||
if (next === undefined) { | ||
res.statusCode = optionsSuccessStatus; | ||
res.end(); | ||
} | ||
next === null || next === void 0 ? void 0 : next(); | ||
}; | ||
};export{cors}; | ||
import{vary}from'es-vary';export var cors=({origin:b="*",methods:g="GET HEAD PUT PATCH POST DELETE".split(" "),allowedHeaders:d,exposedHeaders:e,credentials:h,maxAge:f,optionsSuccessStatus:k=204})=>(l,a,c)=>{"boolean"===typeof b&&!0===b?a.setHeader("Access-Control-Allow-Origin","*"):"string"===typeof b?a.setHeader("Access-Control-Allow-Origin",b):"function"===typeof b&&a.setHeader("Access-Control-Allow-Origin",b(l,a));("string"===typeof b&&"*"!==b||"function"===typeof b)&&vary(a,"Origin");a.setHeader("Access-Control-Allow-Methods", | ||
g.join(", ").toUpperCase());d&&a.setHeader("Access-Control-Allow-Headers",d);e&&a.setHeader("Access-Control-Expose-Headers",e);h&&a.setHeader("Access-Control-Allow-Credentials","true");f&&a.setHeader("Access-Control-Max-Age",f);void 0===c&&(a.statusCode=k,a.end());null===c||void 0===c?void 0:c()} |
{ | ||
"name": "@tinyhttp/cors", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "tinyhttp CORS module", | ||
@@ -40,3 +40,5 @@ "type": "module", | ||
"devDependencies": { | ||
"@ampproject/rollup-plugin-closure-compiler": "^0.26.0", | ||
"rollup": "^2.22.0", | ||
"rollup-plugin-filesize": "^9.0.2", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
@@ -43,0 +45,0 @@ "typescript": "^3.9.7" |
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
9337
5
73
2