mirror of
https://dev.azure.com/tstanciu94/PhantomMind/_git/Bitip
synced 2025-10-13 01:52:19 +03:00
refactor: remove runtime configuration file and update API key handling in services
This commit is contained in:
parent
e6fd321813
commit
66141c696b
@ -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: '/',
|
|
||||||
};
|
|
@ -7,29 +7,18 @@ import {
|
|||||||
ReleaseNotesResponse,
|
ReleaseNotesResponse,
|
||||||
OverviewResponse,
|
OverviewResponse,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
import config from './config';
|
||||||
|
import { pathCombine } from '@/utils/paths';
|
||||||
|
|
||||||
/**
|
const isDevelopment = config.MODE === 'development';
|
||||||
* 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 BASE_URL = isDevelopment
|
const BASE_URL = isDevelopment
|
||||||
? pathCombine(import.meta.env.VITE_API_URL, '/api')
|
? pathCombine(config.VITE_API_URL, '/api')
|
||||||
: '/api';
|
: '/api';
|
||||||
|
|
||||||
const apiClient = axios.create({
|
const apiClient = axios.create({
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
headers: {
|
headers: {
|
||||||
'X-API-Key': API_KEY,
|
'X-API-Key': config.API_KEY,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
const runtimeEnv = window.env || {};
|
const runtimeEnv = window.env || {};
|
||||||
const compileEnv = import.meta.env;
|
const compileEnv = import.meta.env;
|
||||||
|
|
||||||
|
const API_KEY = runtimeEnv.FRONTEND_API_KEY || compileEnv.VITE_API_KEY;
|
||||||
const DEBOUNCE_MS =
|
const DEBOUNCE_MS =
|
||||||
runtimeEnv.DEBOUNCE_MS || parseInt(compileEnv.VITE_DEBOUNCE_MS);
|
runtimeEnv.DEBOUNCE_MS || parseInt(compileEnv.VITE_DEBOUNCE_MS);
|
||||||
|
|
||||||
const processedEnv = {
|
const processedEnv = { API_KEY, DEBOUNCE_MS };
|
||||||
DEBOUNCE_MS,
|
|
||||||
};
|
|
||||||
|
|
||||||
const env = { ...compileEnv, ...runtimeEnv, ...processedEnv };
|
const env = { ...compileEnv, ...runtimeEnv, ...processedEnv };
|
||||||
export default env;
|
export default env;
|
||||||
|
1
src/frontend/src/utils/index.ts
Normal file
1
src/frontend/src/utils/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './paths';
|
13
src/frontend/src/utils/paths.ts
Normal file
13
src/frontend/src/utils/paths.ts
Normal file
@ -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 };
|
@ -18,7 +18,13 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noFallthroughCasesInSwitch": true
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
|
||||||
|
/* Path mapping */
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { defineConfig, loadEnv } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
@ -11,6 +12,11 @@ export default defineConfig(({ mode }) => {
|
|||||||
base: basePath,
|
base: basePath,
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
publicDir: 'public',
|
publicDir: 'public',
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': path.resolve(__dirname, './src'),
|
||||||
|
},
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: '../../dist/frontend',
|
outDir: '../../dist/frontend',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user