I receive this error: Access to XMLHttpRequest at 'https://simplify-pilot-a.i.tgcloud.io:9000/requesttoken?secret=nvg...ecvl&lifetime=1000000' from origin 'http://localhost:8100' 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.
I’m using tgcloud v. 3.4.0
Please advise…
Thanks!
Mor
Hi Yusuf, thank you for your reply and pointer!
My app is an Angular + Ionic mobile app. When using Angular’s HttpClient - I’m getting hit with the CORS issue. When using plain Java from a local server (http-server) - I’m getting through just fine (even though I’m still sending from localhost:9000!).
Maybe I’m missing something, but the tgcloud server is by definition a cloud service that should serve requests from any origin, any domain. CORS should be defined and open on the tgcloud server side. Am I missing something?
Anyway, I’d like to avoid another http server within my Angular app, if possible. Your code seems like a solid server-side, plain JS implementation.
Hey Bruno, many thanks!
Have I entered it correctly? I’ve restarted the server after adding this value, but still denied on CORS with the same error. See here:
I can’t restrict to one client. This will be a mobile app many people will use from around the world. As Bruno indicated, asterisk usually means “all”, but it’s still not working for me…
@morsagmon I just made a curl request to your server but cannot see the header being there: curl -H "origin: localhost" -v "https://simplify-pilot-a.i.tgcloud.io:9000/echo"
Hi Bruno.
I just restarted it now (I thought it was enough to restart the NgInx server after changing the CORS param).
Can you please check now?
The app is still returning the CORS error, but I do get a response using your curl echo request.
Can you please check if there is an OPTION call before GET ?
I still see the same header when using curl. Will later start a cloud instance and test. Maybe it’s bug.
I’m not sure I understand this option.
I don’t really have a middleware (unless the Angular server is considered as such).
This is an Angular/Ionic app that should send requests to the tgcloud service.
Angular has a strong httpClient service that I’m using for other cloud services (including Google FireBase) without a problem. Why should tgcloud be any different?
I thought that you are using Java (as mentioned in your first post). For a plain JavaScript (2-tier) application, CORS is sending OPTIONS before GET/POST - this is a browser security feature.
Since TG Nginx proxy is not processing OPTIONS, you get the error message and the request for token generation fails.
Can you please change the request encoding for this call to 'Content-Type': 'application/x-www-form-urlencoded'
It may help in this case.
I asked my engineers to check the issue, 2-tier apps would all have the same issue.
Thanks Bruno.
I set the headers with the content-type you specified, no change.
(In the first message I mentioned that Java (should be JS actually) is working fine to emphasize it is only related to calls made from Angular. I tested it outside Angular just to verify I’m not doing anything wrong on my end. It is working OK outside of Angular here!).