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

@tinyhttp/cors

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/cors - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

6

CHANGELOG.md
# @tinyhttp/cors
## 0.2.7
### Patch Changes
- Compress whitespace
## 0.2.6

@@ -4,0 +10,0 @@

37

dist/index.js

@@ -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

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