Skip to content

Commit dfedb2b

Browse files
committed
fix: use tokens for api url
1 parent 0d5ffc4 commit dfedb2b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

frontend/src/app/data-providers/engine-data-provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function createClient(
4444
export const createGlobalContext = (opts: {
4545
engineToken: (() => string) | string;
4646
}) => {
47-
const client = createClient(getConfig().apiUrl, {
47+
const client = createClient(engineEnv().VITE_APP_API_URL, {
4848
token: opts.engineToken,
4949
});
5050
return {

frontend/src/components/lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const ConfigContext = createContext<Config>({
2323
export const useConfig = () => useContext(ConfigContext);
2424
export const ConfigProvider = ConfigContext.Provider;
2525

26-
const getApiEndpoint = (apiEndpoint: string) => {
26+
export const getApiEndpoint = (apiEndpoint: string) => {
2727
if (apiEndpoint === "__AUTO__") {
2828
if (location.hostname.startsWith("hub.")) {
2929
// Connect to the corresponding API endpoint

frontend/src/lib/env.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import z from "zod";
2+
import { getApiEndpoint } from "../components/lib/config";
23

34
export const commonEnvSchema = z.object({
4-
VITE_APP_API_URL: z.string(),
5+
VITE_APP_API_URL: z.string().transform((url) => {
6+
return getApiEndpoint(url);
7+
}),
58
VITE_APP_ASSETS_URL: z.string().url(),
69
VITE_APP_POSTHOG_API_KEY: z.string().optional(),
710
VITE_APP_POSTHOG_API_HOST: z.string().url().optional(),
@@ -19,7 +22,9 @@ export const engineEnv = () => commonEnvSchema.parse(import.meta.env);
1922

2023
export const cloudEnvSchema = commonEnvSchema.merge(
2124
z.object({
22-
VITE_APP_API_URL: z.string().url(),
25+
VITE_APP_API_URL: z.string().transform((url) => {
26+
return getApiEndpoint(url);
27+
}),
2328
VITE_APP_CLOUD_ENGINE_URL: z.string().url(),
2429
VITE_APP_CLOUD_API_URL: z.string().url(),
2530
VITE_APP_CLERK_PUBLISHABLE_KEY: z.string(),

0 commit comments

Comments
 (0)