https://github.com/kkpoon/lambda-cors
A CORS handler for AWS Lambda
https://github.com/kkpoon/lambda-cors
api-gateway aws-lambda cors
Last synced: about 1 year ago
JSON representation
A CORS handler for AWS Lambda
- Host: GitHub
- URL: https://github.com/kkpoon/lambda-cors
- Owner: kkpoon
- License: apache-2.0
- Created: 2017-07-03T13:38:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-15T05:09:16.000Z (about 6 years ago)
- Last Synced: 2025-03-04T06:03:56.939Z (over 1 year ago)
- Topics: api-gateway, aws-lambda, cors
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/lambda-cors
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lambda-cors
## Installation
```shell
npm install lambda-cors
```
## Usage
In AWS API Gateway, it could ONLY set one origin for CORS.
To allow multiple origins, we could delay the CORS check to lambda execution.
This library adds the CORS headers automatically to the response.
```javascript
var CORS = require("lambda-cors");
var cors = CORS({
origins: ["http://domain1.com", "http://domain2.com"];
})
exports.handler = cors(function(event, context, callback) {
// ... your request handler
var res = { statusCode: 200, body: "Hello" };
callback(null, res);
});
```