JSPM

aws-lambda-cors

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 59
  • Score
    100M100P100Q59091F
  • License MIT

CORS Library for AWS Lambda with APIGateway.

Package Exports

  • aws-lambda-cors

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aws-lambda-cors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

AWS Lambda CORS

Build Downloads Version License
dependencies Status devDependencies Status

CORS Library for AWS Lambda with APIGateway.

Installation

npm install aws-lambda-cors --save

Usage

import { cors } from 'aws-lambda-cors'

const originLambdaHandler = async (event, ctx) => {
  return {
    statusCode: 200,
    body: '',
  })
}

// Also OK.
//
// const originLambdaHandler = (event, ctx, callback) => {
//   callback(null, {
//     statusCode: 200,
//     body: '',
//   })
// }

export const lambdaHandler = cors({
  allowCredentials: true,
  allowOrigins: [
    'http://localhost:8000',
    'https://wani.kr',
  ],
  allowMethods: [
    'OPTIONS',
    'HEAD',
    'GET',
    'POST',
  ],
  allowHeaders: [
    'Authorization',
    'Content-Type',
  ],
  allowCredentials: true,
})(originLambdaHandler)