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.19 to 0.2.20

6

CHANGELOG.md
# @tinyhttp/cors
## 0.2.20
### Patch Changes
- Split app into req, res, send and router
## 0.2.19

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

11

dist/index.d.ts
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from 'http';
interface AccessControlOptions {
origin?: string | boolean | ((req: IncomingMessage, res: ServerResponse) => string);
import { IncomingMessage as Request, ServerResponse as Response } from 'http';
export interface AccessControlOptions {
origin?: string | boolean | ((req: Request, res: Response) => string);
methods?: string[];

@@ -16,4 +15,2 @@ allowedHeaders?: string[];

*/
declare const cors: ({ origin, methods, allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus, }: AccessControlOptions) => (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
export { AccessControlOptions, cors };
export declare const cors: ({ origin, methods, allowedHeaders, exposedHeaders, credentials, maxAge, optionsSuccessStatus, }: AccessControlOptions) => (req: Request, res: Response, next?: () => void) => void;

@@ -1,39 +0,39 @@

// 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();
};
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
};
export { cors };
{
"name": "@tinyhttp/cors",
"version": "0.2.19",
"version": "0.2.20",
"description": "tinyhttp CORS module",

@@ -39,9 +39,5 @@ "type": "module",

"license": "MIT",
"devDependencies": {
"tsup": "^3.6.1",
"typescript": "^4.0.2"
},
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts"
"build": "rollup -c ../../build/defaultConfig.js"
}
}

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