Socket
Socket
Sign inDemoInstall

@fastify/cors

Package Overview
Dependencies
Maintainers
20
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/cors - npm Package Compare versions

Comparing version 8.4.2 to 8.5.0

2

index.js

@@ -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.2",
"version": "8.5.0",
"description": "Fastify CORS",

@@ -47,3 +47,3 @@ "main": "index.js",

"fastify-plugin": "^4.0.0",
"mnemonist": "0.39.5"
"mnemonist": "0.39.6"
},

@@ -50,0 +50,0 @@ "tsd": {

@@ -357,3 +357,3 @@ 'use strict'

const fastify = Fastify()
fastify.register(cors, () => (a, b, c) => { })
fastify.register(cors, () => (a, b, c) => {})

@@ -946,34 +946,1 @@ 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)

@@ -365,1 +365,74 @@ }

})
test('Should support ongoing prefix ', t => {
t.plan(12)
const fastify = Fastify()
fastify.register(async (instance) => {
instance.register(cors)
}, { prefix: '/prefix' })
// support prefixed route
fastify.inject({
method: 'OPTIONS',
url: '/prefix',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})
// support prefixed route without / continue
fastify.inject({
method: 'OPTIONS',
url: '/prefixfoo',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})
// support prefixed route with / continue
fastify.inject({
method: 'OPTIONS',
url: '/prefix/foo',
headers: {
'access-control-request-method': 'GET',
origin: 'example.com'
}
}, (err, res) => {
t.error(err)
delete res.headers.date
t.equal(res.statusCode, 204)
t.equal(res.payload, '')
t.match(res.headers, {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
vary: 'Origin, Access-Control-Request-Headers',
'content-length': '0'
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc