fix(aws-lambda): return outgoing cookies on response objects
🔗 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: 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 I think the other issue should be resolved with https://github.com/unjs/nitro/pull/356.
@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": "..."
}