Connect to uplink on a self-hosted instance?

I’m trying to connect to uplink on a self-hosted instance. I am starting it with this command:

/home/user/.local/bin/anvil-app-server --app projectname/ --origin https://websitename --uplink-key code

Here is my uplink code:

    anvil.server.connect("password", url="ws://websitename/_/uplink")

The problem is I get this error:

When seeing this, I assumed it was because I was using the wrong port, so I looked in the terminal and saw this:

[INFO  anvil.core.server] HTTP Server running on port 51731
[INFO  anvil.app-server.run] App URL:  https://websitename
[INFO  anvil.app-server.dispatch] Launching built-in downlink...
[INFO  anvil.app-server.run] SMTP Server running on port 25
Connecting to ws://localhost:51731/_/downlink

Notice it says the port 51731. I opened the port 51731 on my router and tried connecting to it with that port, and it worked. But when I restarted the Anvil app, the port changed! Every time I restart it, it shows a new port in the terminal. I don’t want to constantly change ports in my router settings. And in the docs, it says that I’m suppost to use the regular port I’m hosting my app on, which is 80/443 (but as I said in the beginning, it failed). My website uses HTTPS, if that helps. What port/URL am I suppost to use? Thanks in advance for help.

Hi,

The anvil app server is running on a random port behind the bundled traefik, which is used to handle TLS. As the uplink code is using a websocket over TLS, could you try changing the uplink url to use the wss scheme instead of ws?

1 Like

Thank you, that worked. In the docs, it says ws://. I don’t know if it suppost to be that way, but if it was changed to wss://, I think that would avoid a lot of confusion.

1 Like

Hi @TricolorHen061,

Thanks for pointing out that the documentation is unclear. I will get that changed!

1 Like