Skip to content

Commit 4133bc0

Browse files
committed
feat(webapp): read internal-api-origin global default from the flags registry
Resolve the global default from the cached DB feature-flags snapshot so the admin global toggle takes effect, with INTERNAL_API_ORIGIN_ENABLED as the fallback when unset. Load organization.featureFlags only when INTERNAL_API_ORIGIN is configured.
1 parent d90a794 commit 4133bc0

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type LoaderFunctionArgs, json } from "@remix-run/server-runtime";
22
import { z } from "zod";
33
import { prisma } from "~/db.server";
4+
import { env } from "~/env.server";
45
import { authenticateApiRequest } from "~/services/apiAuth.server";
56
import { resolveVariablesForEnvironment } from "~/v3/environmentVariables/environmentVariablesRepository.server";
67

@@ -44,7 +45,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
4445
},
4546
include: {
4647
parentEnvironment: true,
47-
organization: { select: { featureFlags: true } },
48+
// Feeds resolveProdApiOrigin; only loaded when internal-origin routing is possible.
49+
...(env.INTERNAL_API_ORIGIN ? { organization: { select: { featureFlags: true } } } : {}),
4850
},
4951
});
5052

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { env } from "~/env.server";
77
import { getSecretStore } from "~/services/secrets/secretStore.server";
88
import { deduplicateVariableArray } from "../deduplicateVariableArray.server";
99
import { removeBlacklistedVariables } from "../environmentVariableRules.server";
10-
import { resolveInternalApiOriginEnabled } from "../featureFlags";
10+
import { FEATURE_FLAG, resolveInternalApiOriginEnabled } from "../featureFlags";
11+
import { globalFlagsRegistry } from "../globalFlagsRegistry.server";
1112
import { generateFriendlyId } from "../friendlyIdentifiers";
1213
import {
1314
type CreateEnvironmentVariables,
@@ -917,7 +918,6 @@ export const RuntimeEnvironmentForEnvRepoPayload = {
917918
organizationId: true,
918919
branchName: true,
919920
builtInEnvironmentVariableOverrides: true,
920-
organization: { select: { featureFlags: true } },
921921
},
922922
} as const;
923923

@@ -1151,8 +1151,9 @@ async function resolveOverridableOtelDevVariables(
11511151
// Deployed runs normally get the public API origin. When INTERNAL_API_ORIGIN is
11521152
// set and the org's internalApiOriginEnabled flag resolves on (org override wins
11531153
// in both directions; INTERNAL_API_ORIGIN_ENABLED is the global default applied
1154-
// only when the org has not set it), they get the internal origin instead. Reads
1155-
// the in-memory org flags, so a flag change takes effect on the next attempt.
1154+
// only when the org has not set it), they get the internal origin instead. The
1155+
// global default is the cached DB flag with INTERNAL_API_ORIGIN_ENABLED as the
1156+
// fallback; org flags are read in-memory, so a flip applies on the next attempt.
11561157
function resolveProdApiOrigin(runtimeEnvironment: RuntimeEnvironmentForEnvRepo): string {
11571158
const publicOrigin = env.API_ORIGIN ?? env.APP_ORIGIN;
11581159

@@ -1162,7 +1163,9 @@ function resolveProdApiOrigin(runtimeEnvironment: RuntimeEnvironmentForEnvRepo):
11621163

11631164
const enabled = resolveInternalApiOriginEnabled({
11641165
orgFeatureFlags: runtimeEnvironment.organization?.featureFlags,
1165-
globalDefault: env.INTERNAL_API_ORIGIN_ENABLED === "1",
1166+
globalDefault:
1167+
globalFlagsRegistry.current()?.[FEATURE_FLAG.internalApiOriginEnabled] ??
1168+
env.INTERNAL_API_ORIGIN_ENABLED === "1",
11661169
});
11671170

11681171
return enabled ? env.INTERNAL_API_ORIGIN : publicOrigin;

apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
544544
},
545545
include: {
546546
parentEnvironment: true,
547-
// Feeds resolveProdApiOrigin (internal-api-origin flag) without a query.
548-
organization: { select: { featureFlags: true } },
547+
// Feeds resolveProdApiOrigin; only loaded when internal-origin routing is possible.
548+
...(env.INTERNAL_API_ORIGIN ? { organization: { select: { featureFlags: true } } } : {}),
549549
},
550550
});
551551

0 commit comments

Comments
 (0)