fastify-cors
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
type OriginCallback = (err: Error | null, allow: boolean) => void; | ||
type OriginFunction = (origin: string, callback: OriginCallback) => void; | ||
export type OriginFunction = (origin: string, callback: OriginCallback) => void; | ||
type OriginType = string | boolean | RegExp; | ||
@@ -9,0 +9,0 @@ type ValueOrArray<T> = T | ArrayOfValueOrArray<T>; |
{ | ||
"name": "fastify-cors", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Fastify CORS", | ||
@@ -35,11 +35,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@types/node": "^13.13.4", | ||
"@typescript-eslint/eslint-plugin": "^2.10.0", | ||
"@typescript-eslint/parser": "^2.0.0", | ||
"@types/node": "^14.0.1", | ||
"@typescript-eslint/eslint-plugin": "^3.0.1", | ||
"@typescript-eslint/parser": "^3.0.1", | ||
"cors": "^2.8.5", | ||
"fastify": "^3.0.0-rc.1", | ||
"fastify": "^3.0.0", | ||
"standard": "^14.0.2", | ||
"tap": "^14.10.7", | ||
"typescript": "^3.5.3", | ||
"tsd": "^0.11.0" | ||
"tsd": "^0.13.1" | ||
}, | ||
@@ -46,0 +46,0 @@ "dependencies": { |
@@ -8,3 +8,3 @@ # fastify-cors | ||
Supports Fastify versions `3.x` | ||
Please refer to [this branch](https://github.com/fastify/fastify-cors/tree/3.x) and related versions for Fastify `^3.x` compatibility. | ||
Please refer to [this branch](https://github.com/fastify/fastify-cors/tree/3.x) and related versions for Fastify `^2.x` compatibility. | ||
Please refer to [this branch](https://github.com/fastify/fastify-cors/tree/1.x) and related versions for Fastify `^1.x` compatibility. | ||
@@ -11,0 +11,0 @@ |
import fastify from 'fastify' | ||
import fastifyCors from '..' | ||
import fastifyCors, {OriginFunction} from '..' | ||
@@ -80,10 +80,12 @@ const app = fastify() | ||
const corsDelegate: OriginFunction = (origin, cb) => { | ||
if (typeof origin === 'undefined' || /localhost/.test(origin)) { | ||
cb(null, true) | ||
return | ||
} | ||
cb(new Error(), false) | ||
}; | ||
app.register(fastifyCors, { | ||
origin: (origin: string, cb: (err: Error | null, allow: boolean) => void) => { | ||
if (/localhost/.test(origin) || typeof origin === 'undefined') { | ||
cb(null, true) | ||
return | ||
} | ||
cb(new Error(), false) | ||
}, | ||
origin: corsDelegate, | ||
allowedHeaders: ['authorization', 'content-type'], | ||
@@ -176,4 +178,4 @@ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], | ||
appHttp2.register(fastifyCors, { | ||
origin: (origin: string, cb: (err: Error | null, allow: boolean) => void) => { | ||
if (/localhost/.test(origin) || typeof origin === 'undefined') { | ||
origin: (origin: string | undefined, cb: (err: Error | null, allow: boolean) => void) => { | ||
if (typeof origin === 'undefined' || /localhost/.test(origin)) { | ||
cb(null, true) | ||
@@ -180,0 +182,0 @@ return |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33173
890
0