How to fix CORS + failed to load resource: net::err_failed happening only in the first request

Daniel 5 Reputation points
2024-03-04T09:28:40.29+00:00

I have a frontend and backend both deployed on Azure app service.

The problem is the first request from the FE to the BE after some inactive time usually fails with the following errors,

User's image

The backend app logs don't show anything, it seems like the request didn't reach the backend. So maybe the backend is sleeping because of the inactivity? But why do we get the CORS error? I have configured CORS for the backend. To fix the sleeping issue, I have turned on the AlwaysOn feature and also added an availability ping that checks the health of the backend every 15 minutes, I thought that should make it available all the time.

Although the health pings are successful all the time, this request( which is much heavier than the health pings, involves sending images and detection using a model, and takes a fairly long time ) always fails on the first try and succeeds on subsequent requests.

Can someone help me with this?

Thanks in advance.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,628 questions
{count} votes

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.