Moorage

Get your projects ready for Moorage

To get the most out of it: several copies at once, each one wired to itself and never clashing with the others.

The idea in one sentence: nothing that changes between copies can be hard-coded. Ports and URLs are read from the environment; Moorage sets them for each copy when starting it, and they win over whatever the .env says.

How it works

1. The port is chosen from outside

Each copy needs its own ports. If the code says listen(3000), two copies clash. The port must come from a parameter or from PORT:

Project Command in the template
Node / Express node app.js + variable PORT={{port}}, and in the code listen(process.env.PORT || 3000)
Next.js next dev -p {{port}}
Vite, Astro, Nuxt vite --port {{port}} · astro dev --port {{port}}
Expo expo start --port {{port}}
Laravel php artisan serve --port={{port}}
CodeIgniter, PHP php -d variables_order=EGPCS -S {{host.lan}}:{{port}} -t public (see point 3)
Django python manage.py runserver 0.0.0.0:{{port}}

Moorage detects this and suggests the command when creating the template. Make sure no two services share a base port: two services on 3000 clash inside the same copy.

2. Other services' URLs, in variables

Copy 2's web must talk to copy 2's API, not the original's. So the addresses of the other services go in variables (NEXT_PUBLIC_API_URL, VITE_API_URL, EXPO_PUBLIC_API_URL, API_URL…), never hard-coded:

// Wrong: every copy talks to the same API
fetch('http://192.168.1.35:8082/users')

// Right: each copy its own
fetch(`${process.env.NEXT_PUBLIC_API_URL}/users`)

And in the template, you tell each service where the others are with {{service.url}}:

web   →  NEXT_PUBLIC_API_URL    = {{api.url}}
         NEXT_PUBLIC_SOCKET_URL = {{socket.url}}
app   →  EXPO_PUBLIC_API_URL    = {{api.url}}
socket → API_URL                = {{api.url}}

You don't need to type them: when creating the stack, Moorage reads each project's .env and, if a URL points to another service's port (API_URL=http://localhost:8080), suggests replacing it with {{api.url}}. In an existing template, use “Detect connections”, or “Connect to” in a service's “Variables and connections” tab.

If a service is usually parked (you don't run it locally), don't point the others at it: leave them the production URL from the .env. Otherwise that feature will fail locally.

3. The .env: shared values and secrets

4. CORS: let your copies in locally

If your API or socket only accepts a fixed list of origins (http://localhost:3003), copy 2's web (:3103) gets blocked. In development, accept any port on localhost and your local network, switched on with a variable you don't set in production:

// development .env: CORS_ALLOW_LOCAL=1
const allowLocal = process.env.CORS_ALLOW_LOCAL === '1'
const isLocal = (o) => /^https?:\/\/(localhost|127\.0\.0\.1|192\.168\.\d+\.\d+|10\.\d+\.\d+\.\d+)(:\d+)?$/.test(o)

app.use(cors({ origin: (o, cb) => cb(null, !o || allowed.includes(o) || (allowLocal && isLocal(o))) }))

5. If there's a mobile app

6. The database

Cookies ignore ports: two copies open on the same host share the session. With separate data, open each copy under a different name (localhost, 127.0.0.1, your IP).

The template in Moorage

Variables you can use in each service's command and variables:

Variable What it is
{{port}}, {{url}} This service's port and URL in this copy
{{api.port}}, {{api.url}} Another service's, in the same copy (by its key)
{{host.lan}}, {{host.localhost}} Your local network IP, or localhost
{{instance.name}}, {{instance.offset}} The copy's name and its port offset

In each service's “Startup” tab also check: “Starts after” and “Ready when the output contains” (to start in order), “Exclusive group” if only one can run at a time, and “Restart automatically if it crashes”. If something is off (two services on the same port, one that doesn't receive its port, a variable that doesn't exist), the template warns you at the top with a one-click fix.

For your team

Check it's right