# Public URL and Socket.io

**URL:** <https://forums.balena.io/t/public-url-and-socket-io/352644>\
**Category:** Product support\
**Tags:** support\
**Created:** [February 16, 2022, 2:04pm UTC](https://forums.balena.io/t/public-url-and-socket-io/352644 "2022-02-16T14:04:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![emalinen](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@emalinen](https://forums.balena.io/u/emalinen)\
**Post date:** [February 16, 2022, 2:04pm UTC](https://forums.balena.io/t/public-url-and-socket-io/352644/1 "2022-02-16T14:04:45Z")

</div>

Hello! Has anyone successfully communicated between client browser and [Socket.io](http://Socket.io) server running on Balena device (Raspberry Pi in this case) over public URL?

I have working local websocket connection (ws://), but now I need to access camera from browser with WebRTC and it requires encrypted connection. Long polling https connection to public URL returns “bad request” and wss connection throws error: “WebSocket connection to ‘wss://UUID.balena-devices.com/socket.io/?EIO=4&transport=websocket&sid=gCPktkkfTuZxD3oMABDA’ failed: WebSocket is closed before the connection is established.”

RPi has Caddy container listening :80 and reverse proxying to [Socket.io](http://Socket.io) server.

---

<div class="post-metadata">

**Author:** ![jmakivic](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jmakivic](https://forums.balena.io/u/jmakivic)\
**Post date:** [February 16, 2022, 2:55pm UTC](https://forums.balena.io/t/public-url-and-socket-io/352644/2 "2022-02-16T14:55:08Z")

</div>

Hi @emalinen , I have managed to communicate between a client browser and [socket.io](http://socket.io) server running on a Balena device (over RPi) over a public url. Although, in my case I did not require a secure connection. A clarifying question: Is the browser and camera which you are trying to access connected to your Raspberry Pi or is it hosted elsewhere?

---

<div class="post-metadata">

**Author:** ![emalinen](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@emalinen](https://forums.balena.io/u/emalinen)\
**Post date:** [February 17, 2022, 6:56am UTC](https://forums.balena.io/t/public-url-and-socket-io/352644/4 "2022-02-17T06:56:56Z")

</div>

Browser and camera is on a client device (pc, smartphone). Frontend React app is used for reading QR codes. I’m using [react-qr-reader](https://github.com/react-qr-reader/react-qr-reader), which works flawlessly when using unencrypted localhost connection. But when the app is served from Raspberry Pi with static IP in the local network, browser blocks access to getUserMedia() function for privacy reasons. Camera feed is not sent anywhere over the unsecure network, only content of the QR code is sent to RPi.

Public url would be easy way to create encrypted connection, but I have not yet figured out why it does not work.

---

<div class="post-metadata">

**Author:** ![emalinen](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@emalinen](https://forums.balena.io/u/emalinen)\
**Post date:** [February 24, 2022, 12:56pm UTC](https://forums.balena.io/t/public-url-and-socket-io/352644/5 "2022-02-24T12:56:18Z")

</div>

This was a CORS problem caused by [Socket.io](http://Socket.io) server. Adding “[balena-devices.com](http://balena-devices.com)” as allowed origin solved the problem.

Detailed solution for Python server is here: [How to fix "Access-Control-Allow-Origin" error in a python socket-io server - Stack Overflow](https://stackoverflow.com/questions/57579110/how-to-fix-access-control-allow-origin-error-in-a-python-socket-io-server)

---

<div class="post-metadata">

**Author:** ![jmakivic](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@jmakivic](https://forums.balena.io/u/jmakivic)\
**Post date:** [February 24, 2022, 2:41pm UTC](https://forums.balena.io/t/public-url-and-socket-io/352644/6 "2022-02-24T14:41:32Z")

</div>

@emalinen I’m glad you found a solution! Thanks for sharing it here! Also, feel free to keep us updated on your project. You can share any updates on your project in our show and tell forums: [Show and Tell - balenaForums](https://forums.balena.io/c/show-and-tell/92) .
