From 042b14b7d6bbd5ddf1ca73482c6c9dcfa57304f9 Mon Sep 17 00:00:00 2001 From: Ken Browning <98360425+ken-browning@users.noreply.github.com> Date: Mon, 2 Oct 2023 02:14:32 -0700 Subject: [PATCH] Fix type of OriginCallback (#272) --- types/index.d.ts | 2 +- types/index.test-d.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 0abf15f..9fdcef1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,7 +2,7 @@ import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify'; -type OriginCallback = (err: Error | null, allow: boolean) => void; +type OriginCallback = (err: Error | null, origin: ValueOrArray) => void; type OriginType = string | boolean | RegExp; type ValueOrArray = T | ArrayOfValueOrArray; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 9e83223..6e17445 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -117,6 +117,18 @@ app.register(fastifyCors, { strictPreflight: false }) +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 }) appHttp2.register(fastifyCors)