@tinyhttp/cors
Advanced tools
Comparing version 0.1.26 to 0.2.0
@@ -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
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
Network access
Supply chain riskThis module accesses the network.
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
5944
10
76
3
2