Env contract
A feature works end to end only if every project knows its own URL and its neighbours'. AspenX generates the values; your projects read them from env.
Emails, redirects, CORS, cookies, websockets and signed links all depend on each service knowing where it and its neighbours live. Inside a feature those addresses belong to that feature alone, so nothing can be hardcoded. This page is the contract between AspenX and your projects.
Two URLs per project
| Kind | Used for | Feature invoice-pdf, project api |
|---|---|---|
| Public URL | Anything a browser or an email reader follows: links, redirects, CORS origins, cookies, OAuth callbacks. | https://api.invoice-pdf.aspenx.localhost |
| Internal URL | Server-to-server calls between containers. | http://api:3000 on the feature’s compose network |
Inside a container, extra_hosts resolves the feature’s hostnames to the Mac. A public URL therefore reaches Caddy and verifies against the mounted CA. Server-to-server calls should still use the internal URL. It stays on the compose network, skips TLS and Caddy, and also reaches projects with public: false.
In the manifest, {{ url x }} is the public URL and {{ internal_url x }} the internal one. Both always point inside the feature. While a review app is on, {{ url x }} is the public review hostname, which resolves through public DNS rather than extra_hosts.
What AspenX sets
The generated override sets these for every service of every project:
| Variable | Value |
|---|---|
ASPENX_FEATURE |
The feature name. |
ASPENX_PUBLIC_DOMAIN |
The manifest’s public_domain, when set. |
NODE_EXTRA_CA_CERTS, SSL_CERT_FILE |
The Caddy local CA, mounted read-only into every project service, so server-side HTTPS calls to feature hostnames verify. A feature does not start until aspenx init has exported the CA. |
Everything under the project’s env: |
With templates resolved. |
ASPENX_FEATURE, ASPENX_PUBLIC_DOMAIN, NODE_EXTRA_CA_CERTS and SSL_CERT_FILE win over same-named keys under env:.
The override also:
- adds
extra_hostsentries that map thepostgres_serviceandredis_servicenames,host.docker.internaland every local feature hostname (includingmail.<feature>.<local_domain>) to the Mac; - runs a referenced project’s
main_image.servicesfrom its main image, withpull_policy: never,buildreset, and the base file’s volumes replaced by the CA mount; - declares each
shared.volumesentry as the external volumeaspenx-<name>; - removes host ports from projects with
public: false; - drops
depends_onentries for the shared services.
AspenX copies the main checkout’s .env.docker into the feature folder once, when the feature has none.
.aspenx/env holds the variables for compose interpolation, in this order, later values winning:
- every variable of the main checkout’s
.env; - everything under
compose_env:; ASPENX_FEATURE,ASPENX_SLOT,ASPENX_ROOTandCOMPOSE_PROJECT_NAME(aspenx-<feature>).
For mail, each feature runs a Mailpit container named mail. It takes SMTP on port 1025 inside the network, accepts any credentials, and shows its inbox at https://mail.<feature>.<local_domain>.
What your projects should read
The names are yours. These are the conventional ones and what each drives:
| Variable | Set on | Drives |
|---|---|---|
APP_URL |
Every project, as its own public URL. | URL helpers and mailers, the asset host, OAuth redirect URIs. |
<PROJECT>_URL |
One per neighbour. | Links and redirects into other projects. |
<PROJECT>_INTERNAL_URL |
One per neighbour. | API calls between services. |
CORS_ORIGINS |
APIs the browser calls. | The allowlist: the feature’s front-end origins. |
ALLOWED_HOSTS |
Web frameworks and dev servers that reject unknown hosts. | .<feature>.<local_domain>, or .<local_domain> to cover every feature at once. Add .<public_domain> (from ASPENX_PUBLIC_DOMAIN) if you use tunnels or review apps. |
SESSION_COOKIE_DOMAIN |
Projects that share a session. | {{ cookie_domain }}, which is .<feature>.<local_domain>, or .<public_domain> while a review app is on. |
CABLE_ALLOWED_ORIGINS |
Websocket servers. | The origins allowed to connect. |
SMTP_HOST, SMTP_PORT |
Anything that sends mail. | mail and 1025. |
A front end built once into a main image must read API URLs at runtime, never at build time, because the same image serves every feature that pins the same commit. A per-feature config endpoint or an env.js works. Dev servers need their HMR websocket to go through Caddy on 443.
Why cookies need the parent domain
Browsers scope cookies by host, not by port. Two features on localhost:4100 and localhost:4200 share cookies, so signing in to one signs you out of the other.
AspenX puts the project first and the feature second in the hostname. Every project of a feature then shares the parent .<feature>.<local_domain>. The browser sends a session cookie scoped there to every project in the feature and never to another feature. While a review app is on, the cookie domain is .<public_domain>, which every review app shares.
Checking the contract
aspenx doctor --hosts invoice-pdf
This command:
- prints each project’s effective URL env;
- fetches every touched public project’s
healthpath through Caddy; - runs a CORS preflight from each front end to each API whose env lists the front end’s URL in a variable named like
*ORIGIN*or*CORS*; - opens the websocket where
cableis set; - sends a test email with
doctor_mail, run in the project’s first service, and checks that its links point into the feature.
A health fetch fails on a connection or TLS error, or on a 502 to 504. The CORS and websocket checks cover public projects. All checks use the local hostnames, and the command exits 1 when any fails.
Plain aspenx doctor also looks for hardcoded neighbours. It scans for localhost:<port> or 127.0.0.1:<port> in the base file’s service environment (keys the manifest does not override), in the main checkout’s .env and .env.docker, and in every feature’s .aspenx/env.