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

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.

×
Submit an Answer
2 answers

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!

by Seth Gwartney
Learn how to build a real-time document collaboration app using Angular and the Socket.IO realtime application framework.

👋 @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.

  • I am getting an error parsing app spec: unknown field "preserve_path_prefix" in apps.AppServiceSpec

    The perservepathprefix isn’t indented and shows inline with the routes in the app spec preview before uploading

    Edit: Oddly enough, VS Code with prettier formatter wasn’t going to work so I tried ATOM. That didn’t work went to notepad, that didn’t work so I tried WordPad and that worked lol. Going to test out the sockets in a second.

    • It sounds like something touched the indentation so perserve_path_prefix was set on the service itself and not the route. But glad to hear you got it to work! Let me know how the websocket test goes