mirror of
https://dev.azure.com/tstanciu94/PhantomMind/_git/Bitip
synced 2025-10-13 01:52:19 +03:00
refactor: add FRONTEND_API_KEY to runtime config and update API key retrieval logic
This commit is contained in:
parent
64b13b3df0
commit
fcbea476a5
@ -1,6 +1,7 @@
|
|||||||
import { writeFileSync, existsSync } from 'fs';
|
import { writeFileSync, existsSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import logger from './logger.js';
|
import logger from './logger.js';
|
||||||
|
import config from './config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the runtime configuration file (env.js) for the frontend
|
* Generates the runtime configuration file (env.js) for the frontend
|
||||||
@ -32,6 +33,7 @@ export function generateRuntimeConfig(
|
|||||||
// Generate env.js content
|
// Generate env.js content
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
basePath: basePath || '/',
|
basePath: basePath || '/',
|
||||||
|
FRONTEND_API_KEY: config.apiKeys.frontend,
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
@ -8,6 +8,7 @@ declare global {
|
|||||||
interface Window {
|
interface Window {
|
||||||
env?: {
|
env?: {
|
||||||
basePath?: string;
|
basePath?: string;
|
||||||
|
FRONTEND_API_KEY: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ const pathCombine = (baseUrl: string, path: string): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const isDevelopment = import.meta.env.MODE === 'development';
|
const isDevelopment = import.meta.env.MODE === 'development';
|
||||||
const API_KEY = import.meta.env.VITE_API_KEY || 'frontend-default-key';
|
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(import.meta.env.VITE_API_URL, '/api')
|
||||||
: '/api';
|
: '/api';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user