0

admin:1 Access to XMLHttpRequest at '/dev/directjobfinder/listing.json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

IT'S WORKING FINE IN POSTMAN BUT WHEN IM USING AXIOS.PUT THEN IT'S GIVING THE ABOVE ERROR SOMEONE PLEASE HELP I'M STUCKED FROM LAST 2 DAYS

I HAVE DONE Access-Control-Allow-Headers : * Access-Control-Allow-Origin : *'

CORS CONFIG file of S3 bucket [ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "GET", "PUT" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [] } ]

EDIT : ERROR DETAILS SCREENSHOT

  • Does this answer your question? [Why does my http://localhost CORS origin not work?](https://stackoverflow.com/questions/10883211/why-does-my-http-localhost-cors-origin-not-work) – Anon Coward Mar 19 '23 at 18:16

3 Answers3

0

CORS config on the S3 bucket should allow OPTIONS method for a preflight request.

Alex Chadyuk
  • 1,421
  • 2
  • 10
  • [ { "AllowedHeaders": [ "Origin", "Content-Type", "Action" ], "AllowedMethods": [ "GET", "PUT" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [] } ] CORS config for s3 bucket , I'm not able to add OPTION in allowedMethods Found unsupported HTTP method in CORS config. Unsupported method is OPTIONS – kushagra mishra Mar 20 '23 at 07:22
  • for option Found unsupported HTTP method in CORS config. Unsupported method is OPTION – kushagra mishra Mar 20 '23 at 07:27
0

ANSWER : I was calling the api using axios and my method was POST but the problem was in the response header , I was passing a javascript object as application/json , there resides the problem itself i just change it to tex/plain then it works fine .

0

make sure OPTIONS returns 200 ok by running the curl command.

curl -X OPTIONS -H "Origin: ORIGIN_URL" --verbose API_ENDPOINT

If not then run the below command

aws apigateway update-integration --rest-api-id YOUR_REST_ID --resource-id YOUR_RESOURCE_ID --http-method OPTIONS --patch-operations op='replace',path='/contentHandling',value='CONVERT_TO_TEXT'

and dont forget to redeploy the API

for more details: AWS API gateway error while making OPTIONS request