Skip to content

Commit f731a99

Browse files
committed
Revert "fix: support for embedded cors for route params (#278)"
This reverts commit 9acbafe.
1 parent 79b3de9 commit f731a99

File tree

3 files changed

+4
-37
lines changed

3 files changed

+4
-37
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function fastifyCors (fastify, opts, next) {
7272
// remove most headers (such as the Authentication header).
7373
//
7474
// This route simply enables fastify to accept preflight requests.
75-
fastify.options('/*', { schema: { hide: hideOptionsRoute } }, (req, reply) => {
75+
fastify.options('*', { schema: { hide: hideOptionsRoute } }, (req, reply) => {
7676
if (!req.corsPreflightEnabled) {
7777
// Do not handle preflight requests if the origin option disabled CORS
7878
reply.callNotFound()

test/cors.test.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ test('Should support dynamic config. (Invalid function)', t => {
354354
t.plan(2)
355355

356356
const fastify = Fastify()
357-
fastify.register(cors, () => (a, b, c) => { })
357+
fastify.register(cors, () => (a, b, c) => {})
358358

359359
fastify.get('/', (req, reply) => {
360360
reply.send('ok')
@@ -942,36 +942,3 @@ test('Should support wildcard config /2', t => {
942942
t.equal(res.headers['access-control-allow-origin'], '*')
943943
})
944944
})
945-
946-
test('should support embedded cors registration with route params', t => {
947-
t.plan(3)
948-
949-
const fastify = Fastify()
950-
951-
const custom = async (instance, opts) => {
952-
instance.register(cors, {
953-
origin: ['example.com']
954-
})
955-
956-
instance.get('/route1', (req, reply) => {
957-
reply.send('ok')
958-
})
959-
}
960-
961-
fastify.register(custom, {
962-
prefix: '/:id'
963-
})
964-
965-
fastify.inject({
966-
method: 'OPTIONS',
967-
url: '/id1/route1',
968-
headers: {
969-
'access-control-request-method': 'GET',
970-
origin: 'example.com'
971-
}
972-
}, (err, res) => {
973-
t.error(err)
974-
t.equal(res.statusCode, 204)
975-
t.equal(res.headers['access-control-allow-origin'], 'example.com')
976-
})
977-
})

test/preflight.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test('hide options route by default', t => {
189189
const fastify = Fastify()
190190

191191
fastify.addHook('onRoute', (route) => {
192-
if (route.method === 'OPTIONS' && route.url === '/*') {
192+
if (route.method === 'OPTIONS' && route.url === '*') {
193193
t.equal(route.schema.hide, true)
194194
}
195195
})
@@ -206,7 +206,7 @@ test('show options route', t => {
206206
const fastify = Fastify()
207207

208208
fastify.addHook('onRoute', (route) => {
209-
if (route.method === 'OPTIONS' && route.url === '/*') {
209+
if (route.method === 'OPTIONS' && route.url === '*') {
210210
t.equal(route.schema.hide, false)
211211
}
212212
})

0 commit comments

Comments
 (0)