Question

Websocket connection failed error

I had previously tried setting up Nginx with a Droplet but wasn’t successful. I deleted the Droplet and then deployed my app from the Apps service. The app is live but I’m getting the error:

“WebSocketClient.js:13 WebSocket connection to ‘wss://website.io:8080/ws’”.

Is it possible that some bad configuration from the Droplet and Nginx was leftover and is causing this conflict?

Thanks


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 1, 2023
Accepted Answer

Hi there,

I think that when instantiating the web socket, you should not add the port as it is not publicly exposed on the App Platform.

Instead you should do something like this:

const protocol = window.location.protocol.includes('https') ? 'wss': 'ws'
const ws = new WebSocket(`${protocol}://${location.host}/ws`);

Here is a great step by step tutorial that covers the whole process specifically for the App Platform:

https://docs.digitalocean.com/tutorials/app-deploy-websockets/


UPDATE:

It looks like that this is a standard thing for some React apps:

What you have to do is to define an environment variable in your app platform and define the WDS_SOCKET_PORT variable and set it to 443 rather than the default value.

You can check that this would already work by visiting your website and in the web console run:

new WebSocket('wss://domain.io/ws');

Let me know if you have any questions!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel