skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    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 .


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

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search