Skip to content

kkpoon/lambda-cors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda-cors

Installation

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.

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);
});