diff --git a/src/frontend/public/env.js b/src/frontend/public/env.js deleted file mode 100644 index 1547e27..0000000 --- a/src/frontend/public/env.js +++ /dev/null @@ -1,6 +0,0 @@ -// Runtime configuration generated at container startup -// DO NOT EDIT - This file is automatically generated -// eslint-disable-next-line no-undef -window.env = { - BASE_PATH: '/', -}; diff --git a/src/frontend/src/services/api.ts b/src/frontend/src/services/api.ts index 26b78bc..506a4d2 100644 --- a/src/frontend/src/services/api.ts +++ b/src/frontend/src/services/api.ts @@ -7,29 +7,18 @@ import { ReleaseNotesResponse, OverviewResponse, } from '../types'; +import config from './config'; +import { pathCombine } from '@/utils/paths'; -/** - * Combines base URL and path, ensuring proper slash handling - * @param baseUrl - Base URL (e.g., 'http://localhost:5172' or 'http://localhost:5172/') - * @param path - Path to append (e.g., '/api' or 'api') - * @returns Combined URL path - */ -const pathCombine = (baseUrl: string, path: string): string => { - const trimmedBase = baseUrl.replace(/\/+$/, ''); // Remove trailing slashes - const trimmedPath = path.replace(/^\/+/, ''); // Remove leading slashes - return `${trimmedBase}/${trimmedPath}`; -}; - -const isDevelopment = import.meta.env.MODE === 'development'; -const API_KEY = window.env?.FRONTEND_API_KEY || import.meta.env.VITE_API_KEY; +const isDevelopment = config.MODE === 'development'; const BASE_URL = isDevelopment - ? pathCombine(import.meta.env.VITE_API_URL, '/api') + ? pathCombine(config.VITE_API_URL, '/api') : '/api'; const apiClient = axios.create({ baseURL: BASE_URL, headers: { - 'X-API-Key': API_KEY, + 'X-API-Key': config.API_KEY, 'Content-Type': 'application/json', }, timeout: 10000, diff --git a/src/frontend/src/services/config.ts b/src/frontend/src/services/config.ts index cfb5d96..c1f528a 100644 --- a/src/frontend/src/services/config.ts +++ b/src/frontend/src/services/config.ts @@ -1,12 +1,11 @@ const runtimeEnv = window.env || {}; const compileEnv = import.meta.env; +const API_KEY = runtimeEnv.FRONTEND_API_KEY || compileEnv.VITE_API_KEY; const DEBOUNCE_MS = runtimeEnv.DEBOUNCE_MS || parseInt(compileEnv.VITE_DEBOUNCE_MS); -const processedEnv = { - DEBOUNCE_MS, -}; +const processedEnv = { API_KEY, DEBOUNCE_MS }; const env = { ...compileEnv, ...runtimeEnv, ...processedEnv }; export default env; diff --git a/src/frontend/src/utils/index.ts b/src/frontend/src/utils/index.ts new file mode 100644 index 0000000..4a38559 --- /dev/null +++ b/src/frontend/src/utils/index.ts @@ -0,0 +1 @@ +export * from './paths'; diff --git a/src/frontend/src/utils/paths.ts b/src/frontend/src/utils/paths.ts new file mode 100644 index 0000000..67e5727 --- /dev/null +++ b/src/frontend/src/utils/paths.ts @@ -0,0 +1,13 @@ +/** + * Combines base URL and path, ensuring proper slash handling + * @param baseUrl - Base URL (e.g., 'http://localhost:5172' or 'http://localhost:5172/') + * @param path - Path to append (e.g., '/api' or 'api') + * @returns Combined URL path + */ +const pathCombine = (baseUrl: string, path: string): string => { + const trimmedBase = baseUrl.replace(/\/+$/, ''); // Remove trailing slashes + const trimmedPath = path.replace(/^\/+/, ''); // Remove leading slashes + return `${trimmedBase}/${trimmedPath}`; +}; + +export { pathCombine }; diff --git a/src/frontend/tsconfig.json b/src/frontend/tsconfig.json index a7fc6fb..ce9024e 100644 --- a/src/frontend/tsconfig.json +++ b/src/frontend/tsconfig.json @@ -18,7 +18,13 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + /* Path mapping */ + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index cdc43a6..f66df92 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -1,5 +1,6 @@ import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; +import path from 'path'; // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { @@ -11,6 +12,11 @@ export default defineConfig(({ mode }) => { base: basePath, plugins: [react()], publicDir: 'public', + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, build: { outDir: '../../dist/frontend', },