Articles in this section

Set up a WebSocket route

To use the WebSocket protocol on a route, cache must be disabled because WebSocket is incompatible with buffering, which is a requirement for the router caching.

"https://{default}/ws":
    type: upstream
    upstream: "myapp:http"
    cache:
        enabled: false

Let’s break this down.

  1. "https://{default}/ws":
    • https:// - since there's no http:// route configured, http:// will automatically redirect to https://.
    • {default} tells Upsun to use the default domain assigned to your project. This is especially useful if your project doesn't have a domain added yet. That said, you could type a static value such as my-domain.com
    • /ws - you’re telling Upsun that any request to /ws (https://{default}/ws) should be handled by this route definition. If your development environment was sending websocket requests to e.g. https://localhost/my/websocket, you should replace /ws with /my/websocket. Use the path that your app is configured to work with.
  2. type: upstream - normally you won’t change this. This just lets Upsun know how we're going to handle requests.
  3. upstream: "myapp:http"
    • This works with type: upstream to let Upsun know which app you want to answer this request.
      • In your .upsun/config.yaml you will have defined a value like name: myapp or name: my-symfony-app. Use whatever value name: is.  In other words, if you use name: my-websocket-app, then in your routes.yaml you will use upstream: "my-websocket-app:http

Once you have this route pointing to your websocket app, you will want to handle the next step, request buffering.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.