refactor: update runtime configuration keys to uppercase and add type declarations

This commit is contained in:
Tudor Stanciu 2025-10-04 19:55:38 +03:00
parent 798025a971
commit 91f667e4c3
4 changed files with 24 additions and 13 deletions

View File

@ -32,7 +32,7 @@ export function generateRuntimeConfig(
// Generate env.js content // Generate env.js content
const envConfig = { const envConfig = {
basePath: basePath || '/', BASE_PATH: basePath || '/',
FRONTEND_API_KEY: config.apiKeys.frontend, FRONTEND_API_KEY: config.apiKeys.frontend,
}; };

View File

@ -2,5 +2,6 @@
// DO NOT EDIT - This file is automatically generated // DO NOT EDIT - This file is automatically generated
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
window.env = { window.env = {
"basePath": "/" "BASE_PATH": "/",
"FRONTEND_API_KEY": "frontend-dev-key"
}; };

View File

@ -3,17 +3,7 @@ import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import App from './App.tsx'; import App from './App.tsx';
// Runtime config loaded from env.js (generated by backend at startup) const basename = window.env.BASE_PATH || '/';
declare global {
interface Window {
env?: {
basePath?: string;
FRONTEND_API_KEY: string;
};
}
}
const basename = window.env?.basePath || '/';
ReactDOM.createRoot(document.getElementById('root')!).render( ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode> <React.StrictMode>

20
src/frontend/src/types/globals.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
/**
* Global type declarations for the Bitip frontend application
* This file contains ambient declarations for global objects and runtime configuration
*/
/**
* Runtime configuration loaded from env.js
* Generated by backend at startup and injected into window object
*/
declare global {
interface Window {
env: {
BASE_PATH: string;
FRONTEND_API_KEY: string;
};
}
}
// This export makes this file a module, which is required for global augmentation
export {};