Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway HTTP API CORS preflight request

I'm using the new API Gateway HTTP to make requests to 3rd party APIs. This works great for GET requests but doesn't work for POST requests due to CORS preflight.

Cors settings in api gateway

When I try to make a request this is the error I get on the chrome console...

Preflight error

From the docs it says to add Access-Control-Allow-Methods to * and Access-Control-Allow-Origin to * but POST requests triggers a pre flight request and this is failing.

Any help appreciated!

like image 443
johnwick0831 Avatar asked Oct 11 '25 08:10

johnwick0831


1 Answers

Double-check your Access-Control-Allow-Headers. If it's missing any headers that are sent on the request it will silently fail.

I had the same issue (works for GET but not POST) because I had forgotten to add the content-type header to the list. This is a common header sent with POST requests and I can see it is missing in your example.

It may also help to examine the failed network requests in the browser console to see which headers are being sent.

like image 144
Mike Rippon Avatar answered Oct 16 '25 09:10

Mike Rippon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!