Search code examples
cordovagowebsocketphonegap-pluginsphonegap-build

How to solve or bypass error websocket: origin not allowed


On my server I'm running gorilla web socket in go and I'm trying to connect from phonegap application with following javascript code:

var conn = new WebSocket("ws://IP:8080/ws");

but I'm getting this error: websocket: origin not allowed on my server.

Is there anything I can do to solve this?

Maybe another phonegap library or fix/update for this kind of connection?

I have tried many examples of phonegap script but non of them worked.

I would like to use that gorilla websocket plugin on my server but as things stand now that is not possible. Thank you


Solution

  • The solution is - to implement your own CheckOrigin function in your websocket.Upgrader{} because default one checks server host and accept client connections only from same host