From 9c84c279efb3ac8c057109da1fa0423a7ad53bca Mon Sep 17 00:00:00 2001 From: Devin Zuczek Date: Tue, 30 Jun 2026 01:04:50 -0400 Subject: [PATCH] move to .env --- .env.example | 6 +++++ .gitignore | 3 --- README.md | 19 ++++++++------- env.example.json | 6 ----- packages/tools/bin/run-wrangler-deploy | 33 +++++++++++++++----------- 5 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 .env.example delete mode 100644 env.example.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..144907a --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Base domain all service hosts are derived from, e.g. accounts.. +RECFLARE_DOMAIN=rec.example.com + +# Optional per-app subdomain overrides, as a compact JSON object keyed by the +# worker's directory name. Defaults to the directory name when unset. +# RECFLARE_SUBDOMAINS={"playersettings":"settings"} diff --git a/.gitignore b/.gitignore index 15c4121..ddec99d 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,3 @@ yarn-error.log* # Agents .claude/settings.local.json - -# Configuration -env.json diff --git a/README.md b/README.md index 6a3296c..dd25f78 100644 --- a/README.md +++ b/README.md @@ -142,12 +142,13 @@ just install **Configure your custom domain:** -`env.json` is the single source of truth for your base domain; it is gitignored, -so each clone needs its own copy. +For local development, set your base domain in a `.env` file at the repo root; it +is gitignored, so each clone needs its own copy. (For CI you can skip the file and +export `RECFLARE_DOMAIN` directly — see below.) ```bash -cp env.example.json env.json -# edit env.json and set "domain" to your domain +cp .env.example .env +# edit .env and set RECFLARE_DOMAIN to your domain ``` `just deploy` resolves the base domain at deploy time and passes it to wrangler — @@ -156,11 +157,11 @@ and the base domain is injected as the `DOMAIN` var so the `ns` service-discover document and the api share-link base URL are built at runtime. Nothing in version control is rewritten; committed `wrangler.jsonc` files have no routes. -The domain is read from the `RECFLARE_DOMAIN` environment variable if set, -otherwise from `env.json`. Per-app subdomain overrides come from -`RECFLARE_SUBDOMAINS` (a JSON object, e.g. `{"playersettings":"settings"}`) or -the `subdomains` key in `env.json`. For CI, set `RECFLARE_DOMAIN` as a secret and -skip `env.json` entirely: +The domain comes from the `RECFLARE_DOMAIN` environment variable; for local dev +that's loaded from `.env`, and an already-exported value (e.g. a CI secret) takes +precedence over the file. Per-app subdomain overrides come from +`RECFLARE_SUBDOMAINS` (a JSON object, e.g. `{"playersettings":"settings"}`). For +CI, set `RECFLARE_DOMAIN` as a secret and skip `.env` entirely: ```bash RECFLARE_DOMAIN=rec.example.com just deploy diff --git a/env.example.json b/env.example.json deleted file mode 100644 index a67d27b..0000000 --- a/env.example.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "domain": "rec.example.com", - "subdomains": { - "playersettings": "settings" - } -} diff --git a/packages/tools/bin/run-wrangler-deploy b/packages/tools/bin/run-wrangler-deploy index 3c17f3c..7e44d33 100755 --- a/packages/tools/bin/run-wrangler-deploy +++ b/packages/tools/bin/run-wrangler-deploy @@ -10,23 +10,28 @@ VERSION=$(get-version) # — committed wrangler.jsonc has no routes, and the base domain is passed as the # DOMAIN var at runtime. # -# Source order: the RECFLARE_DOMAIN env var wins (handy for CI secrets), else the -# gitignored env.json at the repo root. Per-app subdomain overrides come from -# RECFLARE_SUBDOMAINS (a JSON object) or env.json's "subdomains". -if [ -n "${RECFLARE_DOMAIN:-}" ]; then - DOMAIN="$RECFLARE_DOMAIN" - SUBDOMAINS_JSON=${RECFLARE_SUBDOMAINS:-} - [ -n "$SUBDOMAINS_JSON" ] || SUBDOMAINS_JSON='{}' -else - ENV_JSON="$(git rev-parse --show-toplevel)/env.json" - if [ ! -f "$ENV_JSON" ]; then - echo "error: set RECFLARE_DOMAIN or create $ENV_JSON (copy env.example.json)" >&2 - exit 1 +# The domain comes from the RECFLARE_DOMAIN env var. For local dev that's set in a +# gitignored .env at the repo root; in CI it's an exported secret. An already-set +# RECFLARE_DOMAIN wins and skips the file. Per-app subdomain overrides come from +# RECFLARE_SUBDOMAINS (a JSON object, e.g. {"playersettings":"settings"}). +if [ -z "${RECFLARE_DOMAIN:-}" ]; then + ENV_FILE="$(git rev-parse --show-toplevel)/.env" + if [ -f "$ENV_FILE" ]; then + set -a + . "$ENV_FILE" + set +a fi - DOMAIN=$(jq -r '.domain' "$ENV_JSON") - SUBDOMAINS_JSON=$(jq -c '.subdomains // {}' "$ENV_JSON") fi +if [ -z "${RECFLARE_DOMAIN:-}" ]; then + echo "error: RECFLARE_DOMAIN is not set — export it or add it to .env (see .env.example)" >&2 + exit 1 +fi + +DOMAIN="$RECFLARE_DOMAIN" +SUBDOMAINS_JSON=${RECFLARE_SUBDOMAINS:-} +[ -n "$SUBDOMAINS_JSON" ] || SUBDOMAINS_JSON='{}' + DIR=$(basename "$PWD") # Per-app subdomain override, falling back to the worker's directory name. SUBDOMAIN=$(printf '%s' "$SUBDOMAINS_JSON" | jq -r --arg d "$DIR" '.[$d] // $d')