My Angular application is getting random 504 errors when requesting various endpoints of my backend server (.NET).
Why random ?
- The same endpoint can be hit without errors from the same/different user at another moment during the day
- My backend server is serving successfully lots of requests at the same time other users get the 504 errors.
- Sometime my users have 504 errors and sometime they get CORS errors like
Access to fetch at 'https://my-backend-server/endpoint' from origin 'https://my-frontend-app' has been blocked by CORS policy: 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.
What did I try ?
- .NET : Change CORS configuration to
.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
- .NET : Add
.SetIsOriginAllowed((host) => true)
on my CORS policy - Azure : Scale-up my App Services
- Angular : Add an RxJS timeout on my
HttpInterceptor
(the one I use to inject my JWToken) :return next.handle(request).pipe(timeout(this._defaultTimeout));
- Angular : Add ApplicationInsights both on my App Services to better troubleshoot the errors (now I exactly know that a lot of users get these errors everyday ????)
- Angular : Improve my
<meta http-equiv="Content-Security-Policy"
tag to include all external calls in every possible section - Azure : Disable CORS on both my App Services (crashed the apps)
For information, I did not find any pattern on the failed requests (GET, POST), with or without authentication/authorization, during the day or low activity periods (~10pm), different controllers, etc.