Skip to content

Public URLs

A public URL is the address that you open in a browser to reach a service of a workspace. Each workspace has separate public URLs, so two workspaces of one template do not collide. This guide tells how to expose a service, set up your machine one time, and change the form of the URLs.

A public URL has this form:

https://<service>.<workspace>.<domain>:<port>

For example, the storefront service of the workspace shop-a has the URL https://storefront.shop-a.lo. The default domain is lo. The proxy listens on the standard ports 443 and 80, so the URL has no port. If a different program uses one of them, the proxy uses 7443 or 7080, and the URL shows that port.

A proxy gives these URLs. The proxy is Caddy in a container. It receives the request, finds the service from the host name, and sends the request to the host port of that service. The proxy has a local certificate authority (CA). The CA signs the HTTPS certificates of the URLs.

storefront.shop-a.lo127.0.0.1BrowserDNS serverCaddy proxystorefront of shop-astorefront of shop-b

A service that is not exposed has no public URL. Other services reach it through its internal URL.

Set expose: true on the service in the template. A service that is exposed must also have a port.

localspace.yaml
services:
storefront:
repo: storefront
port: 3000
expose: true
  1. Run lo up <workspace>.
  2. Run lo open <workspace> <service>. The browser opens the public URL of the service.

If the workspace has only one exposed service, you can leave out the service name. If it has more than one, lo open lists their names.

To give the URL to a different service, use the reference ${<service>.public_url}. The service must have expose: true. See the references for all the references.

The proxy starts with the first workspace that has a running exposed service. It stays up after that. A workspace that you stop loses its route, and the proxy sends a 404 response for the host name.

Your machine must do two things for the default URLs. It must send the names in the domain .lo to the DNS server of localspace. It must trust the certificate authority of the proxy. You do this one time with one command.

  1. Run lo setup.
  2. Enter your password when sudo prompts for it.

lo shows each command before sudo runs it. lo setup writes a resolver file for the domain. On macOS, the file is /etc/resolver/<domain>. On Linux, it is a file for systemd-resolved. It also adds the CA of the proxy to the trust store of the system.

If you want only one of the two tasks, use these commands:

Command Task
lo proxy dns Shows if the names reach this machine, and the command that sets it up.
lo proxy dns setup Writes the resolver file only.
lo proxy trust Trusts the CA of the proxy only.

If a browser warns about the certificate, restart the browser. Firefox has a separate trust store and does not use the trust store of the system.

By default, each public URL has the name <service>.<workspace>.<domain>. Some systems must have a service with a name in a specific domain. Examples are a redirect address for OAuth, a cookie, or a CORS rule that is for a domain. You give one service such a name in the template. The other services keep the standard name.

localspace.yaml
domains: [acme.com]
services:
api:
expose: true
port: 8000
front:
expose: true
port: 3000
host: front.{workspace}.acme.com

In the workspace shop-a, api has the URL https://api.shop-a.lo. front has the URL https://front.shop-a.acme.com. ${front.public_url} is the second URL.

The proxy makes a certificate for each name. The CA of the proxy signs it. The names are only for this machine. Nothing changes in the public DNS.

Without {workspace} in host, the name is the same for all workspaces. One workspace holds it at a time. lo up for a second workspace stops with the code conflict.

A template comes from a repository. It must not change the name resolution of your machine alone. When the template has a domain that your machine does not answer, lo new and lo up stop and show a prompt:

Template shop wants localspace to answer acme.com on this machine.
Add acme.com? [y/N]

Use one of these ways to agree:

  • Enter y in the terminal, or use --yes.
  • Run lo proxy dns add acme.com.
  • Select Add in the dialog of the dashboard.

localspace adds the domain to dns.domains and records the template that has the domain. A coding agent that uses lo mcp cannot agree. It gets the code conflict and tells you.

Then write the resolver file of the domain, one time. lo proxy dns setup writes the files that are missing, with one sudo prompt. lo proxy dns ls shows each domain, its template, and the names that localspace answers. lo proxy dns rm acme.com removes the domain and its resolver file.

For proxy.domain, the DNS server answers each name with 127.0.0.1. For a domain that you add, it answers only the names that workspaces use, such as front.shop-a.acme.com. It sends each other name, such as www.acme.com, to the resolvers of your network.

localspace writes the list of names again when a workspace with a host is made, started, or removed. The DNS server reads the new list without a restart.

A registrable domain, such as acme.com, hides the real name of the same depth when a workspace uses that name. lo settings and the dashboard show a note for this. A subdomain such as dev.acme.com hides none of the real names.

A browser refuses plain HTTP for names in a top-level domain that is on the HSTS preload list, such as .dev and .app. With https: false for these domains, the URLs do not open. lo settings shows a note. Use https: true.

If the proxy does not answer, run lo proxy restart. The command removes the container of the proxy and the container of the DNS server. Then it starts them again on the same ports. The CA stays, because it is in a volume.

The machine settings in ~/.localspace/config.yaml control the URLs. All keys are optional.

~/.localspace/config.yaml
proxy:
domain: lo
https: true
host: "{service}.{workspace}"
address: domain
ip: loopback
http_port: 80
https_port: 443
dns_port: 7053
Key Default Meaning
domain lo The domain of the host names. It is one or more DNS labels with dots between them, for example lo, test or acme.lo.
https true The scheme of the URLs. A template can set https: true or https: false to override this value for its workspaces.
host {service}.{workspace} The order of the names. The other value is {workspace}.{service}.
address domain domain gives a host name through the proxy. ip gives an IP address and the host port of the service, and uses no proxy.
ip loopback For address: ip only. loopback uses 127.0.0.1. lan uses the address of this machine in your local network.
http_port, https_port 80, 443 The ports of the proxy. If a port is busy, or the container engine cannot publish it, the proxy uses 7080 or 7443.
dns_port 7053 The port of the DNS server on 127.0.0.1.

The three ports must be different. If a port and its fallback (7080 or 7443) are busy, localspace uses the first free port of its range. It remembers it, so the URLs stay the same. lo settings and the Settings page then show the port that the proxy uses, and the program that holds the configured port. When the configured port is free again, lo proxy restart moves the proxy to it.

Use these facts when you select a value:

  • With the domain localhost, the system resolves the names. The DNS server is not necessary and you do not run lo setup for the names.
  • With address: ip, the URLs use HTTP and the host port of each service. There is no proxy, no DNS server and no CA.
  • With ip: lan, other computers in your local network can reach the services at the address of this machine.
  • A browser treats a domain other than localhost as a secure context only through HTTPS. Service workers and Secure cookies work only then.

Run lo settings to see the settings that are in force, an example URL, and the status of the DNS server. The Settings page of the dashboard changes the same settings.

When you change the settings, a service that runs keeps the URL that it started with. The earlier URL continues to work. lo ls shows (restart for new URLs). Run lo restart <workspace> to give the services their new URLs.

With http_port: 80 and https_port: 443, the URLs have no port, for example https://storefront.shop-a.lo. The proxy runs in a container, and the container engine publishes these ports. It must publish ports below 1024:

Container engine Ports below 1024
Docker Desktop, OrbStack and colima on macOS Yes.
Docker on Linux that runs as root Yes.
Rootless Docker No. Lower net.ipv4.ip_unprivileged_port_start, or use ports above 1024.

If the engine cannot publish the port, the proxy does not start, and the error tells which port it is.