0.0.2 • Published 3 years ago

aws-lambda-cors v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

AWS Lambda CORS

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)