diff --git a/frontend/src/api.ts b/frontend/src/api.ts index c38d552..27063c7 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -1,8 +1,18 @@ import axios from 'axios' import { getToken } from './keycloak' +// Determine API base URL based on environment +const getApiBaseUrl = (): string => { + // In production, API is proxied through the same domain at /api + if (import.meta.env.PROD) { + return window.location.origin + '/api' + } + // In development, use localhost backend + return 'http://localhost:5050/api' +} + const api = axios.create({ - baseURL: 'http://localhost:5050/api' + baseURL: getApiBaseUrl() }) api.interceptors.request.use( diff --git a/frontend/src/keycloak.ts b/frontend/src/keycloak.ts index 10f9427..4acda7a 100644 --- a/frontend/src/keycloak.ts +++ b/frontend/src/keycloak.ts @@ -2,10 +2,21 @@ import Keycloak from 'keycloak-js' let keycloak: Keycloak | null = null +// Get base URL from environment or use current origin +const getRedirectUri = (): string => { + // In production, use the current domain + if (import.meta.env.PROD) { + return window.location.origin + '/' + } + // In development, use localhost + return 'http://localhost:3030/' +} + export const initKeycloak = async (): Promise => { console.log('Initializing Keycloak...') const clientId = 'dalex-proto' + const redirectUri = getRedirectUri() keycloak = new Keycloak({ url: 'https://terminus.bluelake.cloud', // Remove trailing slash @@ -16,7 +27,8 @@ export const initKeycloak = async (): Promise => { console.log('Keycloak config:', { url: 'https://terminus.bluelake.cloud', realm: 'dalex-immo-dev', - clientId: clientId + clientId: clientId, + redirectUri: redirectUri }) try { @@ -24,7 +36,7 @@ export const initKeycloak = async (): Promise => { onLoad: 'login-required', checkLoginIframe: false, pkceMethod: 'S256', // Using PKCE for public clients - redirectUri: 'http://localhost:3030/', // Explicit redirect URI + redirectUri: redirectUri, // Use dynamic redirect URI flow: 'standard' // Explicitly use standard (Authorization Code) flow }) @@ -65,6 +77,6 @@ export const getToken = (): string | undefined => { export const logout = (): void => { keycloak?.logout({ - redirectUri: 'http://localhost:3030/' + redirectUri: getRedirectUri() }) } diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts index 3804a43..5660858 100644 --- a/frontend/src/vite-env.d.ts +++ b/frontend/src/vite-env.d.ts @@ -1,4 +1,6 @@ /* eslint-disable */ +/// + declare module '*.vue' { import type { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any>