jeremydaly / jeremydaly/lambda-api
CORS pre-flight OPTIONS not working because of lowercase casting
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 127
- Avg merge
- 31m
- Merged PRs (30d)
- 2
Description
Hi all,
I just picked up lambda-api, and seems like its the perfect solution for my project; however, I have been struggling for hours trying to get CORS to work.
My OPTIONS pre-flight request headers are being properly sent, but they're all lower case, and it's causing my web appl running in Google Chrome to not recognize it as Access-Control-Allow-Origin as this is the error I am receiving from it:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I verified, with postman, that this is the headers coming back from the pre-flight OPTIONS request:
However, noticed that they're all lower case, and thus Google Chrome cannot find Access-Control-Allow-Origin
This is how it's getting received in Google Chrome:
This is how I am providing CORS in my Lambda:
// import AWS Lambda types
import { APIGatewayProxyEventV2, Context } from "aws-lambda";
// import Lambda API default function
import createAPI from "lambda-api";
import { Authorizer, Role } from "./authorizer";
import { ListProducts } from "./products/List";
// instantiate framework
const api = createAPI({});
// ************************************* CORS *************************************
api.options("/*", (req: any, res: any) => {
// Add CORS headers
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, Content-Length, X-Requested-With");
res.sendStatus(200);
});
Please suggest a workaround for current version of Chrome.
Thank you!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the OPTIONS request using the provided api.options("/*", ...) route and inspect how lambda-api returns the configured CORS headers. Trace the response-header handling responsible for lowercase casting, then verify the corrected pre-flight response in Chrome and with Postman.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript, node.js
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100