I am facing the CORS related issue on the cordova iOS Simulator. My app is using socket.io to connect to the server based on netty (https://github.com/mrniko/netty-socketio). I am using the apache web server as proxy to send the requests from client to netty socket.io server.
Firstly, the simulator is sending the Preflight request and handling it properly by the server. Upon the actual request, I see sometimes the following
[Log] success! (cordova.js, line 1413)
[Log] Connection Opened (cordova.js, line 1413)
[Log] d40dd82a-aee7-45e1-a616-0b59b8752378 (cordova.js, line 1413)
[Log] Starting the service (cordova.js, line 1413)
[Error] WebSocket connection to 'ws://10.88.164.62:8080/socket.io/?EIO=3&transport=websocket&sid=d40dd82a-aee7-45e1-a616-0b59b8752378' failed: The operation couldn’t be completed. Socket is not connected
I belive in this case, the device is able to connect to the server with polling and trying to establish the websocket communication (as per socket.io protocol)
In this case on the server side I am receiving and exception “io.netty.handler.codec.CorruptedFrameException: received a frame that is not masked as expected”
Sometimes I am receiving
[Error] cannot parse response
[Error] XMLHttpRequest cannot load http://10.88.164.62:8080/socket.io/?EIO=3&transport=polling&t=1715741460178-2&sid=d40dd82a-aee7-45e1-a616-0b59b8752378 due to access control checks.
[Error] Failed to load resource: cannot parse response (socket.io, line 0)
which means intial polling request is failing.
However, if I run on actual device, I am receiving “Received response code 502 for localhost:8080, unreachable through proxy”
After going through several resources on the internet, I updated my server to handle CORS by handling OPTIONS request and adding headers.
Access-Control-Allow-Origin : Value set to Origin value on the request
Access-Control-Allow-Headers : my-custom-header
Access-Control-Allow-Methods : GET, POST.
I aslo added the following to my httpd conf file.
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "app://localhost"
</IfModule>
my config.xml has the following
<allow-navigation href="*" />
<access origin="*" />
<platform name="ios">
<preference name="hostname" value="10.88.164.62:8080" />
<preference name="scheme" value="app" />
</platform>
Thank you in advance for addressing my issue.