Skip to content

Commit

Permalink
Fix type of OriginCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-browning committed Oct 1, 2023
1 parent 8b3d70b commit 69764ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OriginType>) => void;
type OriginType = string | boolean | RegExp;
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;

Expand Down
12 changes: 12 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 69764ab

Please sign in to comment.