I'm using Angular with the AppGyver suite for a simple CRUD app. My GET and POST requests were working fine to my remote API (PHP REST Server) until i deployed to the cloud. From there, PHP never actually gets the POST data.
I'm opening up CORS access with custom headers in NGINX
Running a tcpdump on my server i found these differences in the headers being sent before and after deploying to the cloud
IOS SIMULATOR::: WORKS----
Content-Length: 26
Accept: application/json, text/plain, */*
Content-Type: application/json
DEPLOY TO CLOUD::: DOESN'T------
Access-Control-Request-Method: POST
Accept: */*
Access-Control-Request-Headers: accept, origin, content-type
Content-Length: 0
I'm guessing its a CORS issue i cannot see... very frustrating!
(also tried using a signed SSL cert instead of straight HTTP, no change)
My NGINX headers:
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Key,accept,origin,content-type,X-Requested-With,steroidsAppId,steroidsApiKey,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header "Access-Control-Request-Method" "POST";
add_header "Access-Control-Allow-Credentials" true;
I managed to figure this out. Not bothering to fully understand CORS was my fault.
However the guys at AppGyver mentioned that the same headers are sent when the app is being tested locally and deployed to the cloud, however this does not appear to be the case...
I noticed by watching my NGINX logs that a "preflight" check was being performed before each request using the OPTIONS verb. Once deployed to the cloud the second request was terminated. I used this config to open up access
https://michielkalkman.com/snippets/nginx-cors-open-configuration.html
If you are using a live server for your REST application, and if you are running into CORS issues. I would suggest, you use Ionic's proxy server to do all your request. You will not run in any OPTION request etc etc.
Check this Scroll to "Advanced serve options" , and then to "Service Proxies"