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.1.26 to 0.2.0

CHANGELOG.md

13

dist/index.d.ts

@@ -1,14 +0,11 @@

/// <reference types="node" />
import { IncomingMessage as Request } from 'http';
import { ServerResponse as Response } from "http";
declare const defaultMethods: string[];
declare const defaultHeaders: string[];
import { IncomingMessage as Request, ServerResponse as Response } from 'http';
export declare const defaultMethods: string[];
export declare const defaultHeaders: string[];
/**
* CORS Middleware
*/
declare const cors: ({ host, methods, headers }: {
export declare const cors: ({ host, methods, headers, }: {
host?: string;
methods?: string[];
headers?: string[];
}) => (_req: Request, res: Response, next?: () => void) => void;
export { defaultMethods, defaultHeaders, cors };
}) => (_req: Request, res: Response, next?: (err?: any) => void) => void;

@@ -1,1 +0,18 @@

const e=["GET","POST","PUT","PATCH","HEAD"],t=["Origin","X-Requested-With","Content-Type"],s=({host:s="*",methods:o=e,headers:n=t})=>{const r="Access-Control-Allow";return(e,t,d)=>{t.setHeader(r+"-Origin",s),t.setHeader(r+"-Headers",n.join(", ")),t.setHeader(r+"-Methods",o.join(", ")),null==d||d()}};export{s as cors,t as defaultHeaders,e as defaultMethods};
import { METHODS } from 'http';
const defaultMethods = METHODS;
const defaultHeaders = ['Origin', 'X-Requested-With', 'Content-Type'];
/**
* CORS Middleware
*/
const cors = ({ host = '*', methods = defaultMethods, headers = defaultHeaders, }) => {
const prefix = 'Access-Control-Allow';
return (_req, res, next) => {
res.setHeader(`${prefix}-Origin`, host);
res.setHeader(`${prefix}-Headers`, headers.join(', '));
res.setHeader(`${prefix}-Methods`, methods.join(', '));
next === null || next === void 0 ? void 0 : next();
};
};
export { cors, defaultHeaders, defaultMethods };
{
"name": "@tinyhttp/cors",
"version": "0.1.26",
"version": "0.2.0",
"description": "tinyhttp CORS module",

@@ -35,3 +35,11 @@ "type": "module",

"author": "v1rtl",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"rollup": "^2.21.0",
"rollup-plugin-typescript2": "^0.27.1",
"typescript": "^3.9.6"
},
"scripts": {
"build": "rollup -c"
}
}

@@ -1,4 +0,8 @@

import { IncomingMessage as Request, ServerResponse as Response } from 'http'
import {
IncomingMessage as Request,
ServerResponse as Response,
METHODS,
} from 'http'
export const defaultMethods = ['GET', 'POST', 'PUT', 'PATCH', 'HEAD']
export const defaultMethods = METHODS

@@ -10,6 +14,10 @@ export const defaultHeaders = ['Origin', 'X-Requested-With', 'Content-Type']

*/
export const cors = ({ host = '*', methods = defaultMethods, headers = defaultHeaders }) => {
export const cors = ({
host = '*',
methods = defaultMethods,
headers = defaultHeaders,
}) => {
const prefix = 'Access-Control-Allow'
return (_req: Request, res: Response, next?: () => void) => {
return (_req: Request, res: Response, next?: (err?: any) => void) => {
res.setHeader(`${prefix}-Origin`, host)

@@ -16,0 +24,0 @@ res.setHeader(`${prefix}-Headers`, headers.join(', '))

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