Connect two apps
Allow one app to call another, and keep the called app private.
Apps cannot reach each other until you connect them. A connection allows one app to call another app on one port. This guide connects a web app, copperfox, to an API, cinderrock, and makes the API private. Networking explains connections.
Before you start
- Two deployed apps in the same project.
- The port the called app listens on. The examples use
8080.
Steps
Create the connection
On the project canvas, drag from the calling app to the called app. The line shows the port.
You can also add it on the Network tab under Connections: choose Outbound, find the other app, enter the port and select Add. Outbound lists the apps this app may call, Inbound the apps that may call it.
lly network connect copperfox cinderrock --port 8080If cinderrock does not serve port 8080 yet, lly adds it as a service port.
The connection takes effect immediately. A service port that was just added takes effect with the next deploy of the called app.
Point the calling app at the called app
If your repository has a .env value that points to the other app, for example API_URL=http://api:8080, LILY links it during configuration and the variable receives the address of that app.
Make the called app private
A private app is not reachable from the internet. Connected apps still reach it.
Open the called app, select the Network tab and select Make app private. The canvas marks private apps with a lock.
lly network cinderrock hideCheck that it worked
lly network copperfox App copperfox
Exposed yes
Hostname copperfox.lilylabs.app
Ports 3000/tcp
Direction From To Port
outbound copperfox cinderrock 8080If it does not work
| What you see | Cause | Fix |
|---|---|---|
| The calling app cannot reach the other app | No connection for that port, or the port was added and the called app was not redeployed | Check lly network cinderrock, then lly redeploy cinderrock |
Exit code 2 | You tried to connect an app to itself | Connect two different apps |
Exit code 4 | The port or connection does not exist | Check the port with lly network cinderrock |
More messages and their fixes: Troubleshooting.
Use an agent
In my LILY project, allow the app "copperfox" to call the app "cinderrock" on port 8080
and make "cinderrock" private.
Run `lly network connect copperfox cinderrock --port 8080`, then `lly network cinderrock hide`,
then show me the output of `lly network copperfox`.