Socket
Socket
Sign inDemoInstall

@middy/http-cors

Package Overview
Dependencies
Maintainers
10
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/http-cors - npm Package Compare versions

Comparing version 1.0.0-alpha.27 to 1.0.0-alpha.28

36

__tests__/index.js

@@ -141,2 +141,8 @@ const middy = require('../../core')

handler.use({
onError: (handler, next) => {
next()
}
})
const event = {

@@ -155,2 +161,17 @@ httpMethod: 'GET'

test('It should not swallow errors', () => {
const handler = middy((event, context, cb) => {
throw new Error('some-error')
})
handler.use(
cors()
)
handler({}, {}, (error, response) => {
expect(response).toBe(undefined)
expect(error.message).toEqual('some-error')
})
})
test('It should not override already declared Access-Control-Allow-Headers header', () => {

@@ -175,2 +196,7 @@ const handler = middy((event, context, cb) => {

}))
handler.use({
onError: (handler, next) => {
next()
}
})

@@ -237,2 +263,7 @@ const event = {

)
handler.use({
onError: (handler, next) => {
next()
}
})

@@ -274,2 +305,7 @@ const event = {

)
handler.use({
onError: (handler, next) => {
next()
}
})

@@ -276,0 +312,0 @@ const event = {

2

index.js

@@ -50,3 +50,3 @@ const defaults = {

next()
next(handler.error)
}

@@ -53,0 +53,0 @@

{
"name": "@middy/http-cors",
"version": "1.0.0-alpha.27",
"version": "1.0.0-alpha.28",
"description": "CORS (Cross-Origin Resource Sharing) middleware for the middy framework",

@@ -44,3 +44,3 @@ "engines": {

},
"gitHead": "0da121c430a512efda580304c7ef3afff76ae2f2"
"gitHead": "89b20f171afbfb801067757114013ac95a411b73"
}

@@ -52,3 +52,27 @@ # Middy CORS middleware

NOTES:
- If another middleware does not handle and swallow errors, then it will bubble all the way up
and terminate the Lambda invocation with an error. In this case API Gateway would return a default 502 response, and the CORS headers would be lost. To prevent this, you should use the `httpErrorHandler` middleware before the `cors` middleware like this:
```javascript
const middy = require('@middy/core')
const httpErrorHandler = require('@middy/http-error-handler')
const cors = require('@middy/http-cors')
const handler = middy((event, context, cb) => {
throw new createError.UnprocessableEntity()
})
handler.use(httpErrorHandler())
.use(cors())
// when Lambda runs the handler...
handler({}, {}, (_, response) => {
expect(response.headers['Access-Control-Allow-Origin']).toEqual('*')
expect(response).toEqual({
statusCode: 422,
body: 'Unprocessable Entity'
})
})
```
## Sample usage

@@ -55,0 +79,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