Skip to content

Commit 2c0ba42

Browse files
committed
fix(webapp): normalize empty RUNTIME_API_ORIGIN to undefined so '??' fallback works
The docker-compose passthrough `RUNTIME_API_ORIGIN: ${RUNTIME_API_ORIGIN:-}` resolves to an empty string when the user hasn't set it, which the nullish coalescing chain (`env.RUNTIME_API_ORIGIN ?? env.API_ORIGIN ?? env.APP_ORIGIN`) doesn't fall through (`??` only treats null/undefined as missing). Result was `TRIGGER_API_URL=""` and `TRIGGER_STREAM_URL=""` reaching runner pods, breaking their webapp connection. Apply the normalization at the schema level via `.transform(v => v || undefined)` so any caller (current docker-compose, future templates) is protected without having to remember to special-case empty strings at each use site. Also clarify in `.env.example` that this var intentionally feeds both TRIGGER_API_URL and TRIGGER_STREAM_URL (keep all runner traffic on the same bypass hop), and tells operators who need a dedicated stream endpoint to use STREAM_ORIGIN instead.
1 parent 3c0455e commit 2c0ba42

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,18 @@ const EnvironmentSchema = z
127127
LOGIN_RATE_LIMITS_ENABLED: BoolEnv.default(true),
128128
APP_ORIGIN: z.string().default("http://localhost:3030"),
129129
API_ORIGIN: z.string().optional(),
130-
// Origin that the webapp publishes to runner pods as `TRIGGER_API_URL`.
131-
// When self-hosting behind a tracing-enabled gateway (Envoy/Istio/etc.)
132-
// that rewrites the W3C `traceparent` on egress, point this at an
133-
// in-cluster service URL so runner-to-webapp traffic stays inside the
134-
// cluster and the parent->child run link in the trace tree is preserved.
135-
// Falls back to API_ORIGIN/APP_ORIGIN, so the existing behavior is
136-
// unchanged when this is unset.
137-
RUNTIME_API_ORIGIN: z.string().optional(),
130+
// Origin that the webapp publishes to runner pods as both `TRIGGER_API_URL`
131+
// and (as the first fallback) `TRIGGER_STREAM_URL`. When self-hosting
132+
// behind a tracing-enabled gateway (Envoy/Istio/etc.) that rewrites the
133+
// W3C `traceparent` on egress, point this at an in-cluster service URL so
134+
// runner-to-webapp traffic stays inside the cluster and the parent->child
135+
// run link in the trace tree is preserved. Empty string is normalized to
136+
// unset so blank `${RUNTIME_API_ORIGIN:-}` passthroughs in
137+
// `docker-compose.yml` don't short-circuit the `??` fallback chain.
138+
RUNTIME_API_ORIGIN: z
139+
.string()
140+
.optional()
141+
.transform((v) => v || undefined),
138142
STREAM_ORIGIN: z.string().optional(),
139143
ELECTRIC_ORIGIN: z.string().default("http://localhost:3060"),
140144
// A comma separated list of electric origins to shard into different electric instances by environmentId

hosting/docker/.env.example

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ API_ORIGIN=http://localhost:8030
4646
DEV_OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8030/otel
4747
# You may need to set this when testing locally or when using the combined setup
4848
# API_ORIGIN=http://webapp:3000
49-
# Optional: origin advertised to runner pods as TRIGGER_API_URL. When unset,
50-
# runners fall back to API_ORIGIN/APP_ORIGIN. Set this to an in-cluster
51-
# service URL when running behind a tracing-enabled gateway that rewrites
52-
# the W3C `traceparent` header on egress (e.g. Envoy/Istio with tracing on).
49+
# Optional: origin advertised to runner pods as both TRIGGER_API_URL and
50+
# TRIGGER_STREAM_URL (intentional: keeps all runner traffic on the same
51+
# bypass hop). When unset, runners fall back to STREAM_ORIGIN/API_ORIGIN/
52+
# APP_ORIGIN as before. Set this to an in-cluster service URL when running
53+
# behind a tracing-enabled gateway that rewrites the W3C `traceparent`
54+
# header on egress (e.g. Envoy/Istio with tracing on). If you need streams
55+
# on a dedicated endpoint (CDN, etc.), keep RUNTIME_API_ORIGIN unset and
56+
# use STREAM_ORIGIN instead.
5357
# RUNTIME_API_ORIGIN=http://webapp:3000
5458

5559
# Webapp - memory management

0 commit comments

Comments
 (0)