Skip to main content

How to connect a mobile app to a backend on localhost

Create an HTTPS tunnel in ProximaClient to the backend's port and set its link as the API address in your app: the phone reaches the backend on your computer from any network, over HTTPS with a real certificate.

A phone doesn't see your computer's localhost and keeps apps off http://, while a ProximaClient link opens in an emulator and on a phone on mobile internet alike: the app needs no http:// or custom certificate settings.

Steps​

  1. Start the backend on your computer, for example on localhost:8000.
  2. In ProximaClient, open "Tunnels" and click "Create tunnel". If you already have tunnels, it's the "+" button above the list.
  3. In "Protocol", pick HTTPS: "A website or API at a link of its own".
  4. In "Destination address", enter the backend's port: localhost:8000.
  5. Click "Create tunnel". Once the tunnel connects, copy the link with the "Copy public address" icon.
  6. Set the link as the API address in your app, for example https://your-link/api, and rebuild the app.

Check that the backend answers from the phone: open the link in the phone's browser. If you see the "Service not responding" page, the backend on your computer isn't running or listens on another port.

Since app version 1.3.0

To skip typing the link on the phone, click the "Show QR code" icon next to the tunnel's address and point the phone's camera at the code: the link opens in the browser.

While the tunnel runs, the link does not change, and how long it is kept after the tunnel closes is on the "An HTTPS link to localhost" page. To avoid rebuilding the app for a new link, keep the API address in a build setting rather than in the code.

How to keep strangers away from the backend​

Since app version 1.3.0

On the tunnel's "Security" tab you can create a key for programs: the app sends it in the X-Proxima-Auth header, and requests without the key don't reach the backend. More on the page about a login and password for the link.