nitro icon indicating copy to clipboard operation
nitro copied to clipboard

fix(aws-lambda): return outgoing cookies on response objects

Open danielroe opened this issue 3 years ago • 2 comments

🔗 Linked issue

resolves #245

❓ Type of change

  • [ ] 📖 Documentation (updates to the documentation or readme)
  • [x] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [ ] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR returns an array of cookies to set from aws-lambda preset rather than keeping them on the headers. More info in AWS docs.

@brtinney - would be grateful if you could confirm this resolves the issue for you.

📝 Checklist

  • [x] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

danielroe avatar Jul 20 '22 13:07 danielroe

@danielroe: It appears to properly set the cookies now, although I still have to use: event.headers.cookie = event.cookies.join("; "); over event.headers.cookie = event.cookies.join(","); in order to use the cookie library to parse them from the event, as the (more common?) convention is to use ; to separate them.

That said, I'm not sure if I can necessarily insist that nitro should be using ; to separate the cookies. I can at least get away with doing parse((req.headers.cookie || '').replace(/,/g, ';')) in my actual code instead of having to modify the built mjs for that particular issue. (Which should be safe since neither , or ; are supposed to actually appear in cookies....)

Thanks!

brtinney avatar Jul 20 '22 22:07 brtinney

@brtinney I think the other issue should be resolved with https://github.com/unjs/nitro/pull/356.

danielroe avatar Jul 21 '22 08:07 danielroe

@pi0 I have tried this and it doesn't work. I configured Amazon API Gateway proxy integration to work with an AWS Lambda function. When I call my endpoint, I receive a configuration error and an HTTP 502 status code.

Execution failed due to configuration error: Malformed Lambda proxy response

This is due to the fact that cookies are returned in the response object. For API Gateway to handle a Lambda function's response, the function must return output according to the following JSON format. Additional fields are not allowed.

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}

rhumie avatar Sep 15 '22 04:09 rhumie