CORS in Static Web App

Dyt13 211 Reputation points
2022-09-27T10:22:22.717+00:00

Hello,

I'm trying to do a very simple fetch("EXTERNAL_URL.",method:"POST") in my static web app and i get the following error msg :

Access to fetch at 'EXTERNAL_URL' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I've tried adding "Access-Control-Allow-Origin": "*" in my request headers but i don't manage to get rid of the issue.

Can you please help with that ?
Thanks

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,024 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,005 questions
0 comments No comments
{count} votes

Accepted answer
  1. DanielV 81 Reputation points
    2022-09-29T17:37:09.9+00:00

    Hi,

    Usually, the CORS configuration must be done on the server handling the request, not on the requester.
    https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api#add-cors-functionality

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.