How to use an external server as an Uplink and to host the web app simultaneously?

Hello,

I am not really familiar with how the Anvil server works in terms of authentication and communication between server, uplink, and client. However, I will try to explain the issue as much as I can, please excuse my English:

1- I created a simple ‘Hello World’ app on anvil online editor, then I tested it and it was working perfectly.

2- I used the external uplink feature to keep my server script on a remote server, and again everything was working like a charm, here is the code:

from ._anvil_designer import Form1Template
from anvil import *
import anvil.server

class Form1(Form1Template):

  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

  def button_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    self.message_label.text = anvil.server.call('get_name', self.name_box.text)
    pass

  def text_box_3_pressed_enter(self, **event_args):
    """This method is called when the user presses Enter in this text box"""
    pass

  def sum_click(self, **event_args):
    """This method is called when the button is clicked"""
    self.result.text = anvil.server.call('add_nums', self.num1.text, self.num2.text)
    pass
and here is the server script which is running on the external uplink:

import anvil.server
anvil.server.connect("UPLINK DERIVED FROM ANVIL ONLINE")

@anvil.server.callable
def get_name(name):
  response = "Hello from the server, %s!" % name
  return response

@anvil.server.callable
def add_nums(num1,num2):
  result = int(num1)+int(num2)
  return result

anvil.server.wait_forever()

3- Now, I tried to clone my app which is on Anvil online via git so I can host it completely from my external server:

git clone ssh://bla@bla.bla@anvil.works:2222/RN35GHXNR4UHW77W.git Hello_World

anvil-app-server --app Hello_World --origin https://somewhere.domain.com

So far so good, the app was loading normally on the browser via the external URL

4- Finally, when I input some data and press the button I end up with this ugly error:

Code Sample:

[ERROR anvil.app-server.run] Error report from client code:
NoServerFunctionError: No server function matching "get_name" has been registered
Traceback:
  app/Hello_World/Form1/__init__.py:15

^CTraceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/melsayeh/env/lib/python3.8/site-packages/anvil_downlink_host/run.py", line 4, in <module>
    anvil_downlink_host.run_downlink_host()
  File "/home/melsayeh/env/lib/python3.8/site-packages/anvil_downlink_host/__init__.py", line 474, in run_downlink_host
    time.sleep(5)

I am pretty sure I am missing something really obvious even though I spent a long time reading through Anvil documentation. Hope to find some guidance here.

Thanks!

Clone link:
share a copy of your app

Could anyone help with this please?

When you start the app server locally, you need to pass it the uplink key you want to use for that app.

Then you need to add that same key to the connect call in your uplink script. You will also need to pass a url argument in that call pointing to your app server.

You can see the options for the app server, including the uplink key, at:

Thanks a lot for your reply.

I am sorry if my question sounds dumb, but is there a specific method/requirement to generate an uplink key or any string would work?
About the URL, do I need to point to the local host (127.0.0.1) or the public/external IP?
One last question, where or to which file can I apply the advanced options, the documentation is a bit vague!

Again, thank you!

It’s all explained in the section describing the uplink key option:

I will say that I had a weird issue where the port I specified didn’t actually work when connecting. What I did was look at the server logs when the system booted up and found the internal web server port (Traefik does a reverse proxy out to port 80) then used that. Really annoying, and I was probably doing something wrong, but that worked for me.