4.4 KiB
Type 2: API on one host, web on another
Use this when the frontend should live on a different server from the database and ingest, or when more than one web frontend should share one API. If one server is enough, use the all-in-one stack in the main README instead.
docker-deployment-type2/
├── server/ API (app), Postgres (db), Redis (redis), Caddy → https://api.example.com
└── web/ web frontend, Caddy → https://beacon.example.com
What you need
- Two hosts with Docker and ports 80 and 443 open.
- Two DNS names pointing at them, for example
api.example.comandbeacon.example.com. - A subscriber account on a MeshCore MQTT broker. See Getting packets in.
Server host
-
Clone this repo on the host and go to the server folder:
git clone https://github.com/MeshCore-Beacon/beacon-docs.git cd beacon-docs/docker-deployment-type2/server -
Create
.envfrom the shared template and fill in everyCHANGE_*value. Only theappandcaddylines matter here; theVITE_*lines can be deleted. If you have one broker, clearMQTT_BROKER_2_URL.cp ../../app_config/.env.example .env nano .envSet
DOMAINto the API hostname (api.example.com) and add one line this stack needs that the all-in-one one does not:WEB_DOMAIN=beacon.example.comCaddy redirects anything that is not
/api/*or/wsto that host. The password insidePOSTGRES_DSNmust matchPOSTGRES_PASSWORDindocker-compose.yml.For MeshMapper imports, set
MESHMAPPER_API_KEYin this server host's.env. Your local MeshMapper regional or grouped-region admin can generate the regional or grouped-region key. Do not copy it to the web host or aVITE_*setting. See MeshMapper API key. -
Edit
data/app/config.yamlfor your network (see Configuration). Because the web app will be served from another origin, browsers may only open the WebSocket if that origin is listed:websocket: allowed_origins: [https://beacon.example.com]server.trusted_proxiesis already set to the compose subnet so Beacon sees real client addresses through Caddy.ingest.allow_countriesis set to[CA]; change it to your country or delete theingestblock, or nothing outside Canada is stored. -
Point DNS for
DOMAINat this host and bring it up:docker compose up -dhttps://api.example.com/api/v1/brokersshould answer with your brokers.
Web host
-
Clone this repo on the host and go to the web folder:
git clone https://github.com/MeshCore-Beacon/beacon-docs.git cd beacon-docs/docker-deployment-type2/web -
Create
.envfrom the template in that folder (cp .env.example .env) and set:Variable Value DOMAINthe web hostname, beacon.example.comBEACON_WEB_IMAGEghcr.io/meshcore-beacon/beacon-web:latestto follow releases like the server half does. To pin instead, pin both halves to the same release line, for example:2.0here andbeacon-server:2.0inserver/docker-compose.yml.VITE_API_BASEhttps://api.example.com/api/v1VITE_WS_URLwss://api.example.com/wsThe optional
VITE_*values are described in Configuration. -
Point DNS for
DOMAINat this host and bring it up:docker compose up -dOpen
https://beacon.example.com. If the page loads but nothing is live, the server host'swebsocket.allowed_originsis the first thing to check; see Troubleshooting.
How the two connect
The browser talks to the API host directly; the web host only serves files. That is why the
API host has to allow the web origin for WebSocket. REST CORS allows any origin by default.
Rate limits and connection caps work the same as in the all-in-one stack because each host's
Caddy sets X-Real-IP and is trusted through server.trusted_proxies; see
Reverse proxy.
To change a VITE_* value later, edit the web host's .env and run
docker compose up -d beacon-web.