Service discovery

The environment variables lo1 sets so services can find each other.

lo1 starts every service, whether it runs from source, from a container image or through a plugin, with variables describing every service in the workspace that has a port and is not skipped, including itself. Service names become upper case keys, with hyphens turned into underscores: shop-api becomes LO1_SERVICE_SHOP_API_URL.

VariableValue
LO1_SERVICE_<NAME>_URLDirect URL to the service.
LO1_SERVICE_<NAME>_PORTPort to reach it on.
LO1_SERVICE_<NAME>_PROXY_URLURL through the proxy, such as https://api.shop.local. Uses http unless TLS is enabled, and ignores custom proxy.domain values.
LO1_SERVICE_NAMEThe name of the service receiving the variables.
LO1_WORKSPACE_NAMEThe workspace name.

The direct URL depends on where the consumer and the target run:

ConsumerTarget in dev modeTarget in a container
Dev modehttp://localhost:<port>http://localhost:<hostPort>
In a containerhttp://host.docker.internal:<port>http://api:3000, on the Compose network

On Linux, lo1 maps host.docker.internal for the containers it runs, so the same URLs work there.

Values you set in a service's env override the discovery variables, except LO1_SERVICE_NAME and LO1_WORKSPACE_NAME. A service's preStart, postStart and preStop hooks get the same variables as the service. Workspace hooks don't get them.

const apiUrl = process.env.LO1_SERVICE_API_URL ?? 'http://localhost:3000';

Last updated on