Unable to get 200 response from an API when a request is sent from localhost:3000

0

When we submit a POST request from localhost:3000 to an API, we got message below in the browser develop console with Status: 404.

x 'Access to fetch at '<Invoke URL>' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If any opaque response serves your needs, set the request mode to 'no-cors' to fetch the resource with CORS disabled'. x POST <invoke URL' net::ERR_FAILED 404

But when we submit the request to the same API from Postman, we got 200 response.

Where could be the problem? Thanks.

1개 답변
2
수락된 답변

Postman does not implement the CORS restriction which are instead a native security browser mechanism.

You should implement CORS at server/backend layer, by allowing the caller (origin) to consume the rest endpoint.

profile picture
전문가
답변함 10달 전
  • Thanks Antonio. We enabled CORS at the resource level in the API. Is that not sufficient? What do you mean by 'implement CORS at server/backend layer'? The backend of the specific method is an ECS service with Node.js runtime.

  • I meant that for Instance, if you use express as backend server, you should look into enabling cors like this: https://expressjs.com/en/resources/middleware/cors.html. Try out and let me know ;)

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠