@lambda-middleware/cors
AWS lambda middleware for automatically adding CORS headers.
Lambda middleware
This middleware is part of the lambda middleware series. It can be used independently.
Usage
import { cors } from "@lambda-middleware/cors";
import { APIGatewayProxyResult } from "aws-lambda";
async function helloWorld(): Promise<APIGatewayProxyResult> {
return {
statusCode: 200,
body: "",
};
}
export const handler = cors({
allowedHeaders: [],
cacheControl: "max-age: 300",
allowCredentials: true,
exposedHeaders: ["X-Custom-Header"],
maxAge: 300,
allowedMethods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
optionsSuccessStatus: 204,
allowedOrigins: ["https://example.com"],
preflightContinue: false,
})(helloWorld);