@fastify/cors
Advanced tools
Comparing version 8.4.0 to 8.4.1
{ | ||
"name": "@fastify/cors", | ||
"version": "8.4.0", | ||
"version": "8.4.1", | ||
"description": "Fastify CORS", | ||
"main": "index.js", | ||
"type": "commonjs", | ||
"types": "types/index.d.ts", | ||
@@ -7,0 +8,0 @@ "scripts": { |
@@ -712,3 +712,3 @@ 'use strict' | ||
const fastify = Fastify() | ||
fastify.register(cors, { origin: /(example|other)\.com/gi }) | ||
fastify.register(cors, { origin: /(?:example|other)\.com/giu }) | ||
@@ -715,0 +715,0 @@ fastify.get('/', (req, reply) => { |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
type OriginCallback = (err: Error | null, allow: boolean) => void; | ||
type OriginCallback = (err: Error | null, origin: ValueOrArray<OriginType>) => void; | ||
type OriginType = string | boolean | RegExp; | ||
@@ -8,0 +8,0 @@ type ValueOrArray<T> = T | ArrayOfValueOrArray<T>; |
@@ -100,3 +100,3 @@ import fastify, { FastifyRequest } from 'fastify' | ||
const corsDelegate: OriginFunction = (origin, cb) => { | ||
if (typeof origin === 'undefined' || /localhost/.test(origin)) { | ||
if (origin === undefined || /localhost/.test(origin)) { | ||
cb(null, true) | ||
@@ -121,2 +121,14 @@ return | ||
app.register(fastifyCors, { | ||
origin: (origin, cb) => cb(null, true) | ||
}) | ||
app.register(fastifyCors, { | ||
origin: (origin, cb) => cb(null, '*') | ||
}) | ||
app.register(fastifyCors, { | ||
origin: (origin, cb) => cb(null, /\*/) | ||
}) | ||
const appHttp2 = fastify({ http2: true }) | ||
@@ -212,3 +224,3 @@ | ||
origin: (origin: string | undefined, cb: (err: Error | null, allow: boolean) => void) => { | ||
if (typeof origin === 'undefined' || /localhost/.test(origin)) { | ||
if (origin === undefined || /localhost/.test(origin)) { | ||
cb(null, true) | ||
@@ -215,0 +227,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
93599
2790