cors-for-lambda

1.0.1 • Public • Published

cors-for-lambda

"cors-for-lambda", is designed to apply CORS Headers for Lambda HTTP responses.

Getting Started

To get started with this project, clone the repository and install the necessary dependencies.

Usage

const cors = require("cors-for-lambda");

exports.handler = async (event) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify("Hello from Lambda!"),
  };
  return cors.corsResponse(response, "*");
};

for multiples sites:

const cors = require("cors-for-lambda");

exports.handler = async (event) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify("Hello from Lambda!"),
  };
  return cors.corsResponse(
    response,
    "https://example.com",
    "https://example2.com"
  );
};

Or

const { responseHeader } = require("cors-for-lambda");

exports.handler = async (event) => {
  const response = {
    statusCode: 200,
    headers: responseHeader("https://example.com", "https://example2.com"),
    body: JSON.stringify("Hello from Lambda!"),
  };
  return response;
};

Contributing

Contributions are welcome. Please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i cors-for-lambda

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

3.04 kB

Total Files

6

Last publish

Collaborators

  • mwg-digital