Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions web/app/api/cli/config/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
defaultHostedSubrouterURL,
hostedSubrouterBaseURL,
} from "@/services/subrouter/constants";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

Expand All @@ -10,6 +15,15 @@ export function GET(request: Request): Response {
if (!projectId || !publishableClientKey) {
return unavailableResponse();
}
let subrouterUrl: string;
try {
subrouterUrl = hostedSubrouterBaseURL(
process.env.SUBROUTER_HOSTED_URL?.trim() ||
defaultHostedSubrouterURL(),
);
} catch {
return unavailableResponse();
}

return Response.json(
{
Expand All @@ -29,6 +43,15 @@ export function GET(request: Request): Response {
accountsUrl: new URL("/api/coderouter/accounts", request.url).toString(),
openaiBaseUrl: new URL("/v1", request.url).toString(),
},
// Keep the hosted Subrouter fields for released sr clients while cmux
// migrates its CodeRouter data plane to Vercel.
subrouter: {
url: subrouterUrl,
exchangeUrl: new URL(
"/api/subrouter/tenant-exchange",
request.url,
).toString(),
},
},
{
headers: {
Expand Down
8 changes: 7 additions & 1 deletion web/tests/cli-config-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ type CliConfigEnvKey =
| "NEXT_PUBLIC_STACK_API_URL"
| "NEXT_PUBLIC_STACK_PROJECT_ID"
| "NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY"
| "SUBROUTER_HOSTED_URL"
| "VERCEL_ENV";

const testEnvironment = {
NEXT_PUBLIC_STACK_API_URL: "https://stack.example.test/api/v1",
NEXT_PUBLIC_STACK_PROJECT_ID: "test-stack-project-id",
NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY: "test-stack-publishable-key",
SUBROUTER_HOSTED_URL: "https://subrouter.example.test",
VERCEL_ENV: "preview",
} satisfies Record<CliConfigEnvKey, string>;

Expand Down Expand Up @@ -46,7 +48,7 @@ async function withCliConfigEnvironment(
}

describe("CLI config route", () => {
test("publishes native Stack Auth and the Vercel CodeRouter data plane", async () => {
test("publishes CodeRouter and the hosted Subrouter POST contract", async () => {
await withCliConfigEnvironment(testEnvironment, async () => {
const response = GET(new Request("https://cmux.com/api/cli/config"));
expect(response.status).toBe(200);
Expand All @@ -65,6 +67,10 @@ describe("CLI config route", () => {
accountsUrl: "https://cmux.com/api/coderouter/accounts",
openaiBaseUrl: "https://cmux.com/v1",
},
subrouter: {
url: testEnvironment.SUBROUTER_HOSTED_URL,
exchangeUrl: "https://cmux.com/api/subrouter/tenant-exchange",
},
});
});
});
Expand Down