@fastify/cors
Advanced tools
Comparing version 8.4.1 to 8.4.2
@@ -75,3 +75,3 @@ 'use strict' | ||
// This route simply enables fastify to accept preflight requests. | ||
fastify.options('*', { schema: { hide: hideOptionsRoute } }, (req, reply) => { | ||
fastify.options('/*', { schema: { hide: hideOptionsRoute } }, (req, reply) => { | ||
if (!req.corsPreflightEnabled) { | ||
@@ -78,0 +78,0 @@ // Do not handle preflight requests if the origin option disabled CORS |
{ | ||
"name": "@fastify/cors", | ||
"version": "8.4.1", | ||
"version": "8.4.2", | ||
"description": "Fastify CORS", | ||
@@ -41,3 +41,3 @@ "main": "index.js", | ||
"standard": "^17.0.0", | ||
"tap": "^16.0.0", | ||
"tap": "16.3.9", | ||
"tsd": "^0.29.0", | ||
@@ -44,0 +44,0 @@ "typescript": "^5.0.2" |
@@ -357,3 +357,3 @@ 'use strict' | ||
const fastify = Fastify() | ||
fastify.register(cors, () => (a, b, c) => {}) | ||
fastify.register(cors, () => (a, b, c) => { }) | ||
@@ -946,1 +946,34 @@ fastify.get('/', (req, reply) => { | ||
}) | ||
test('should support embedded cors registration with route params', t => { | ||
t.plan(3) | ||
const fastify = Fastify() | ||
const custom = async (instance, opts) => { | ||
instance.register(cors, { | ||
origin: ['example.com'] | ||
}) | ||
instance.get('/route1', (req, reply) => { | ||
reply.send('ok') | ||
}) | ||
} | ||
fastify.register(custom, { | ||
prefix: '/:id' | ||
}) | ||
fastify.inject({ | ||
method: 'OPTIONS', | ||
url: '/id1/route1', | ||
headers: { | ||
'access-control-request-method': 'GET', | ||
origin: 'example.com' | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.equal(res.statusCode, 204) | ||
t.equal(res.headers['access-control-allow-origin'], 'example.com') | ||
}) | ||
}) |
@@ -192,3 +192,3 @@ 'use strict' | ||
fastify.addHook('onRoute', (route) => { | ||
if (route.method === 'OPTIONS' && route.url === '*') { | ||
if (route.method === 'OPTIONS' && route.url === '/*') { | ||
t.equal(route.schema.hide, true) | ||
@@ -210,3 +210,3 @@ } | ||
fastify.addHook('onRoute', (route) => { | ||
if (route.method === 'OPTIONS' && route.url === '*') { | ||
if (route.method === 'OPTIONS' && route.url === '/*') { | ||
t.equal(route.schema.hide, false) | ||
@@ -213,0 +213,0 @@ } |
Sorry, the diff of this file is not supported yet
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
94377
2817