Skip to content

devlanes is in beta and not ready for production use.Report an issue

Serve wildcard and tenant subdomains

Use a wildcard hostname when your app answers on a subdomain per tenant or per user, and each lane should have its own set of them.

::example{slug="web-wildcard-tenants"}

When tenants write what their pages contain, keep those pages off the app’s cookie site. The domain function gives them a domain that, like the lane’s domain, carries the lane number:

devlanes.yaml
lanes:
vars:
sites_domain: ${{ domain('myapp-sites') }}

That is myapp-sites.localhost in lane 0 and myapp-sites1.localhost in lane 1. Pick a name no other project uses, ending in a letter.

A hostname that starts with *. matches every name below the rest of it. Quote it, since a leading * means something else in YAML.

devlanes.yaml
services:
sites:
run_script:
file: apps/sites/package.json
name: dev
hosts: "*.${{ lane.sites_domain }}"
env:
SITES_DOMAIN: ${{ lane.sites_domain }}

The service gets the request with its original Host header and reads the tenant from it.

Keep exact hostnames and a fallback beside it

Section titled “Keep exact hostnames and a fallback beside it”

An exact hostname wins over any wildcard, so the app and fixed names stay under the lane’s domain. A wildcard marked as a fallback takes every name nothing else claims, which suits a gateway that answers for unknown names.

devlanes.yaml
services:
app:
run_script:
file: apps/app/package.json
name: dev
hosts: app.${{ lane.domain }}
gateway:
run_script:
file: apps/gateway/package.json
name: dev
hosts:
- host: "*.${{ lane.domain }}"
fallback: true

Start the lane and list its routes, wildcards and the fallback included:

Terminal window
$ devlanes start
$ devlanes url ls

services.<name>.hosts[] lists the fields of a route.

If tenant pages may share the app’s cookies

Section titled “If tenant pages may share the app’s cookies”

Put the tenant wildcard under the lane’s domain, "*.${{ lane.domain }}", without a fallback. It then takes every name the exact hostnames leave, ahead of the gateway.

If a program other than a browser opens a tenant hostname

Section titled “If a program other than a browser opens a tenant hostname”

A hosts file cannot hold wildcards, so such a program needs the resolver strategy from Fix programs that cannot resolve *.localhost.