Skip to content

Commit b1c40b3

Browse files
committed
refactor(webapp): make S2 account and basin hosts env-configurable with cloud defaults
1 parent 5a9b176 commit b1c40b3

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

apps/webapp/app/env.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,8 @@ const EnvironmentSchema = z
21212121
REALTIME_STREAMS_S2_BASIN: z.string().optional(),
21222122
REALTIME_STREAMS_S2_ACCESS_TOKEN: z.string().optional(),
21232123
REALTIME_STREAMS_S2_ENDPOINT: z.string().optional(),
2124+
REALTIME_STREAMS_S2_ACCOUNT_URL: z.string().default("https://a.s2.dev/v1"),
2125+
REALTIME_STREAMS_S2_BASIN_URL: z.string().default("https://{basin}.b.s2.dev/v1"),
21242126
REALTIME_STREAMS_S2_SKIP_ACCESS_TOKENS: z.enum(["true", "false"]).default("false"),
21252127
REALTIME_STREAMS_S2_ACCESS_TOKEN_EXPIRATION_IN_MS: z.coerce
21262128
.number()

apps/webapp/app/services/realtime/s2realtimeStreams.server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export type S2RealtimeStreamsOptions = {
4444

4545
// Custom endpoint for s2-lite (self-hosted)
4646
endpoint?: string; // e.g., "http://localhost:4566/v1"
47+
/** Account-level API base for account/basin ops. Defaults to S2 cloud. */
48+
accountUrl?: string;
49+
/** Per-basin API base, with a `{basin}` placeholder. Defaults to S2 cloud. */
50+
basinUrl?: string;
4751

4852
// Skip access token issuance (s2-lite doesn't support /access-tokens)
4953
skipAccessTokens?: boolean;
@@ -116,8 +120,10 @@ export class S2RealtimeStreams implements StreamResponder, StreamIngestor {
116120

117121
constructor(opts: S2RealtimeStreamsOptions) {
118122
this.basin = opts.basin;
119-
this.baseUrl = opts.endpoint ?? `https://${this.basin}.b.s2.dev/v1`;
120-
this.accountUrl = opts.endpoint ?? `https://a.s2.dev/v1`;
123+
this.baseUrl =
124+
opts.endpoint ??
125+
(opts.basinUrl ?? `https://{basin}.b.s2.dev/v1`).replace("{basin}", this.basin);
126+
this.accountUrl = opts.endpoint ?? opts.accountUrl ?? `https://a.s2.dev/v1`;
121127
this.endpoint = opts.endpoint;
122128
this.token = opts.accessToken;
123129
this.streamPrefix = opts.streamPrefix ?? "";

apps/webapp/app/services/realtime/streamBasinProvisioner.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ type CreateBasinOptions = {
185185
};
186186

187187
async function s2CreateBasin(name: string, opts: CreateBasinOptions): Promise<void> {
188-
const url = `https://a.s2.dev/v1/basins`;
188+
const url = `${env.REALTIME_STREAMS_S2_ACCOUNT_URL}/basins`;
189189
const body = {
190190
basin: name,
191191
config: {
@@ -222,7 +222,7 @@ type ReconfigureBasinOptions = {
222222
};
223223

224224
async function s2ReconfigureBasin(name: string, opts: ReconfigureBasinOptions): Promise<void> {
225-
const url = `https://a.s2.dev/v1/basins/${encodeURIComponent(name)}`;
225+
const url = `${env.REALTIME_STREAMS_S2_ACCOUNT_URL}/basins/${encodeURIComponent(name)}`;
226226
const body = {
227227
default_stream_config: {
228228
retention_policy: { age: parseDuration(opts.retentionPolicy) },

apps/webapp/app/services/realtime/v1StreamsGlobal.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function getRealtimeStreamInstance(
7070
basin: resolvedBasin,
7171
accessToken: env.REALTIME_STREAMS_S2_ACCESS_TOKEN ?? "",
7272
endpoint: env.REALTIME_STREAMS_S2_ENDPOINT,
73+
accountUrl: env.REALTIME_STREAMS_S2_ACCOUNT_URL,
74+
basinUrl: env.REALTIME_STREAMS_S2_BASIN_URL,
7375
skipAccessTokens: env.REALTIME_STREAMS_S2_SKIP_ACCESS_TOKENS === "true",
7476
streamPrefix: streamPrefixFor(environment, resolvedBasin),
7577
logLevel: env.REALTIME_STREAMS_S2_LOG_LEVEL,

0 commit comments

Comments
 (0)