Question

How to connect Socket.io to App Platform

I have been trying to get my socket to connect to my server. I’ve been looking around and it seems I need to send a certificate with it somehow. If I put in the path into the url the page returns {“code”:1,“message”:“Session ID unknown”}. It’s a error 400 in the console.

I found this post, I think he is using a droplet though, but seem like I need to setup something like it. https://www.digitalocean.com/community/questions/socket-io-call-throwing-400-bad-request-for-some-users

I am not using a droplet, I have hosted the react app on the app platform and made the server as component of it with its path at /api. I have configured socket.io to use that path and know it is correct due to the url returning that error code.

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

👋 @larryryan0824

I’m not sure if this is what’s causing the error, but just in case it helps:

made the server as component of it with its path at /api. I have configured socket.io to use that path and know it is correct due to the url returning that error code.

By default, if a component is configured with an HTTP route, the app/code will see incoming requests without the /api prefix. For example, a request coming in to /api/login will be rewritten to /login before being forwarded to the app.

If this is not the desired behavior, you can instruct App Platform to keep the prefix by following these steps:

  1. Navigate to your app in the control panel
  2. Click on the Settings tab
  3. Scroll down and download the App Spec
  4. Find your component’s routes, and set the preserve_path_prefix option to true
  5. Save the file, and upload the new app spec to the control panel.
...
services:
  - name: api
    routes:
      - path: /api
        preserve_path_prefix: true
...

For more info on the app spec, please see the reference.

Hi @larryryan0824,

I can’t say I’ve actually had similar Apps being built so it’s just a short in the dark for me however, I’ve searched around DigitalOcean’s community, docs and tutorials and found those 2, hope they can be of some help until someone else answers this :

https://www.digitalocean.com/community/tutorials/angular-socket-io

https://www.digitalocean.com/community/questions/how-to-deploy-nodejs-socket-io-app-on-digital-ocean-app-engine

Hope this helps!