dherault / dherault/serverless-offline
CORS headers missing when invoking function via aws sdk
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 811
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
## Bug Report
No CORS headers (e.g. Access-Control-Allow-Origin and Access-Control-Allow-Credentials) are present when invoking a function via aws sdk. Deployed lambda works fine.
**Current Behavior**
Error in console
`Access to XMLHttpRequest at 'http://localhost:4001/2015-03-31/functions/serverless-action-exports-dev-exportTable/invocations' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.`
**Sample Code**
- file: serverless.yml
```yaml
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: us-east-1
memorySize: 10240
functions:
exportTable:
handler: src/index.exportTable
timeout: 900
plugins:
- serverless-offline
custom:
serverless-offline:
lambdaPort: 4001
```
**Expected behavior/code**
CORS headers are present and no error in console.
**Environment**
- `serverless` version: [e.g. v3.30.1]
- `serverless-offline` version: [e.g. v12.0.4]
- `node.js` version: [e.g. v14.21.3]
- `OS`: 13.3.1
**Possible Solution**
Looks like need to handle CORS here https://github.com/dherault/serverless-offline/blob/v12.0.4/src/lambda/HttpServer.js same as here https://github.com/dherault/serverless-offline/blob/v12.0.4/src/events/http/HttpServer.js#L107
Adding onPreResponse fixes the issue for me 
**Additional context/Screenshots**

Contributor guide
Assessment
This issue has not been assessed yet.