@tinyhttp/cors
Advanced tools
Comparing version 0.2.14 to 0.2.16
# @tinyhttp/cors | ||
## 0.2.16 | ||
### Patch Changes | ||
- Fix weird problems with internet that I couldn't publish normally | ||
## 0.2.15 | ||
### Patch Changes | ||
- Add proper sub-app support | ||
## 0.2.14 | ||
@@ -4,0 +16,0 @@ |
@@ -1,1 +0,39 @@ | ||
import{vary}from"es-vary";const cors=({origin="*",methods=["GET","HEAD","PUT","PATCH","POST","DELETE"],allowedHeaders,exposedHeaders,credentials,maxAge,optionsSuccessStatus=204})=>{return(req,res,next)=>{if(typeof origin==="boolean"&&origin===!0)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");res.setHeader("Access-Control-Allow-Methods",methods.join(", ").toUpperCase());if(allowedHeaders)res.setHeader("Access-Control-Allow-Headers",allowedHeaders);if(exposedHeaders)res.setHeader("Access-Control-Expose-Headers",exposedHeaders);if(credentials)res.setHeader("Access-Control-Allow-Credentials","true");if(maxAge)res.setHeader("Access-Control-Max-Age",maxAge);if(next===void 0){res.statusCode=optionsSuccessStatus;res.end()}next==null?void 0:next()}};export{cors}; | ||
// src/index.ts | ||
import {vary} from "es-vary"; | ||
const cors = ({ | ||
origin = "*", | ||
methods = ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"], | ||
allowedHeaders, | ||
exposedHeaders, | ||
credentials, | ||
maxAge, | ||
optionsSuccessStatus = 204 | ||
}) => { | ||
return (req, res, next) => { | ||
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"); | ||
res.setHeader("Access-Control-Allow-Methods", methods.join(", ").toUpperCase()); | ||
if (allowedHeaders) | ||
res.setHeader("Access-Control-Allow-Headers", allowedHeaders); | ||
if (exposedHeaders) | ||
res.setHeader("Access-Control-Expose-Headers", exposedHeaders); | ||
if (credentials) | ||
res.setHeader("Access-Control-Allow-Credentials", "true"); | ||
if (maxAge) | ||
res.setHeader("Access-Control-Max-Age", maxAge); | ||
if (next === void 0) { | ||
res.statusCode = optionsSuccessStatus; | ||
res.end(); | ||
} | ||
next == null ? void 0 : next(); | ||
}; | ||
}; | ||
export { | ||
cors | ||
}; |
{ | ||
"name": "@tinyhttp/cors", | ||
"version": "0.2.14", | ||
"version": "0.2.16", | ||
"description": "tinyhttp CORS module", | ||
@@ -44,4 +44,4 @@ "type": "module", | ||
"scripts": { | ||
"build": "tsup src/index.ts --minify-whitespace --format cjs,esm --dts" | ||
"build": "tsup src/index.ts --format cjs,esm --dts" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
10548
141
1