Skip to content

Commit 3398663

Browse files
committed
fix(webapp): scope RUNTIME_API_ORIGIN to managed (deployed) runs only
Dev (CLI) task runs typically execute on a developer's machine outside any cluster, so forcing them onto the runner-bypass origin (which usually points at an in-cluster service URL) would make the URL unreachable. Restore the original API_ORIGIN/APP_ORIGIN chain for resolveBuiltInDevVariables and keep RUNTIME_API_ORIGIN only in resolveBuiltInProdVariables, where managed runner pods inside the cluster are the actual target. Also clarify the scope in env.server.ts and .env.example so operators know to expect dev CLI to keep using the public origin even when RUNTIME_API_ORIGIN is set for prod runners.
1 parent f0f65f0 commit 3398663

3 files changed

Lines changed: 27 additions & 23 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ 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 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.
130+
// Origin that the webapp publishes to MANAGED (deployed) runner pods as
131+
// both `TRIGGER_API_URL` and (as the first fallback) `TRIGGER_STREAM_URL`.
132+
// When self-hosting behind a tracing-enabled gateway (Envoy/Istio/etc.)
133+
// that rewrites the W3C `traceparent` on egress, point this at an
134+
// in-cluster service URL so runner-to-webapp traffic stays inside the
135+
// cluster and the parent->child run link in the trace tree is preserved.
136+
// Intentionally NOT used for dev (CLI) task runs, which usually run on a
137+
// developer's machine outside the cluster and would lose connectivity if
138+
// forced onto an in-cluster URL. Empty string is normalized to unset so
139+
// blank `${RUNTIME_API_ORIGIN:-}` passthroughs from caller environments
140+
// don't short-circuit the `??` fallback chain.
138141
RUNTIME_API_ORIGIN: z
139142
.string()
140143
.optional()

apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,11 @@ async function resolveOverridableTriggerVariables(
963963

964964
/**
965965
* Resolves built-in environment variables that are injected into dev (CLI) task
966-
* runs. `TRIGGER_API_URL` and `TRIGGER_STREAM_URL` prefer `RUNTIME_API_ORIGIN`
967-
* over `API_ORIGIN`/`STREAM_ORIGIN` so self-hosted deployments can keep
968-
* runner-to-webapp traffic on a cluster-internal hop (bypassing tracing-enabled
969-
* gateways that rewrite the W3C `traceparent` header on egress) without
970-
* affecting the public origins exposed to external clients.
966+
* runs. Dev CLI typically runs on a developer's machine outside any cluster,
967+
* so the runner-bypass `RUNTIME_API_ORIGIN` (which usually points at an
968+
* in-cluster service URL) is intentionally NOT applied here -- using it would
969+
* make the URL unreachable for the dev CLI. Dev keeps the original
970+
* `API_ORIGIN`/`STREAM_ORIGIN`/`APP_ORIGIN` chain.
971971
*/
972972
async function resolveBuiltInDevVariables(runtimeEnvironment: RuntimeEnvironmentForEnvRepo) {
973973
let result: Array<EnvironmentVariable> = [
@@ -977,11 +977,11 @@ async function resolveBuiltInDevVariables(runtimeEnvironment: RuntimeEnvironment
977977
},
978978
{
979979
key: "TRIGGER_API_URL",
980-
value: env.RUNTIME_API_ORIGIN ?? env.API_ORIGIN ?? env.APP_ORIGIN,
980+
value: env.API_ORIGIN ?? env.APP_ORIGIN,
981981
},
982982
{
983983
key: "TRIGGER_STREAM_URL",
984-
value: env.RUNTIME_API_ORIGIN ?? env.STREAM_ORIGIN ?? env.API_ORIGIN ?? env.APP_ORIGIN,
984+
value: env.STREAM_ORIGIN ?? env.API_ORIGIN ?? env.APP_ORIGIN,
985985
},
986986
];
987987

hosting/docker/.env.example

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ 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 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.
49+
# Optional: origin advertised to MANAGED (deployed) runner pods as both
50+
# TRIGGER_API_URL and TRIGGER_STREAM_URL (intentional: keeps all managed
51+
# runner traffic on the same bypass hop). Dev (CLI) task runs are NOT
52+
# affected -- they keep using API_ORIGIN/APP_ORIGIN so a developer running
53+
# `trigger.dev dev` from outside the cluster doesn't lose connectivity.
54+
# Set this to an in-cluster service URL when running behind a tracing-enabled
55+
# gateway that rewrites the W3C `traceparent` header on egress (e.g. Envoy/
56+
# Istio with tracing on). If you need streams on a dedicated endpoint (CDN,
57+
# etc.), keep RUNTIME_API_ORIGIN unset and use STREAM_ORIGIN instead.
5758
# RUNTIME_API_ORIGIN=http://webapp:3000
5859

5960
# Webapp - memory management

0 commit comments

Comments
 (0)