Skip to content

Commit

Permalink
feat: better arch
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl committed Oct 22, 2024
1 parent 5be61d0 commit 822ea19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion keep-ui/pages/api/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ export default async function handler(
: undefined,
PUSHER_APP_KEY: process.env.PUSHER_APP_KEY,
PUSHER_CLUSTER: process.env.PUSHER_CLUSTER,
// could be relative (for ingress) or absolute (e.g. for cloud run)
// The API URL is used by the server to make requests to the API
// note that we need two different URLs for the client and the server
// because in some environments, e.g. docker-compose, the server can get keep-backend
// whereas the client (browser) can get only localhost
API_URL: process.env.API_URL,
// could be relative (e.g. for ingress) or absolute (e.g. for cloud run)
API_URL_CLIENT: process.env.API_URL_CLIENT,
POSTHOG_KEY: process.env.POSTHOG_KEY,
POSTHOG_DISABLED: process.env.POSTHOG_DISABLED,
POSTHOG_HOST: process.env.POSTHOG_HOST,
Expand Down
4 changes: 4 additions & 0 deletions keep-ui/types/internal-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export interface InternalConfig {
POSTHOG_KEY: string;
POSTHOG_HOST: string;
POSTHOG_DISABLED: string;
// the API URL is used by the server to make requests to the API
API_URL: string;
// the API URL for the client (browser)
// optional, defaults to /backend (relative)
API_URL_CLIENT?: string;
}
9 changes: 8 additions & 1 deletion keep-ui/utils/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ export const useConfig = () => {

export const useApiUrl = () => {
const { data: config } = useConfig();
return config?.API_URL;

if (config?.API_URL_CLIENT) {
return config.API_URL_CLIENT;
}

// backward compatibility or for docker-compose or other deployments where the browser
// can't access the API directly
return "/backend";
};

0 comments on commit 822ea19

Please sign in to comment.