Skip to content

Commit

Permalink
fix hide options route by default (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarceau authored Jul 14, 2021
1 parent ca5e606 commit 2b84669
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function fastifyCors (fastify, opts, next) {
if (typeof opts === 'function') {
handleCorsOptionsDelegator(opts, fastify)
} else {
hideOptionsRoute = opts.hideOptionsRoute
if (opts.hideOptionsRoute !== undefined) hideOptionsRoute = opts.hideOptionsRoute
const corsOptions = Object.assign({}, defaultOptions, opts)
fastify.addHook('onRequest', (req, reply, next) => {
onRequest(fastify, corsOptions, req, reply, next)
Expand Down
17 changes: 17 additions & 0 deletions test/preflight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ test('Should support a prefix for preflight requests', t => {
})
})

test('hide options route by default', t => {
t.plan(2)

const fastify = Fastify()

fastify.addHook('onRoute', (route) => {
if (route.method === 'OPTIONS' && route.url === '*') {
t.equal(route.schema.hide, true)
}
})
fastify.register(cors)

fastify.ready(err => {
t.error(err)
})
})

test('show options route', t => {
t.plan(2)

Expand Down

0 comments on commit 2b84669

Please sign in to comment.