Fix API routing
This commit is contained in:
@@ -146,7 +146,7 @@ app.get('/version', async (req, res) => {
|
|||||||
const localVersion = process.env.VERSION;
|
const localVersion = process.env.VERSION;
|
||||||
|
|
||||||
if (!localVersion) {
|
if (!localVersion) {
|
||||||
return res.status(401).send('Local Version Not Set');
|
return res.status(404).send('Local Version Not Set');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -160,38 +160,24 @@ interface OIDCAuthorize {
|
|||||||
|
|
||||||
export function setCookie(name: string, value: string, days = 7): void {
|
export function setCookie(name: string, value: string, days = 7): void {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
||||||
console.log('setCookie - isElectron:', isElectron, 'storing:', name, 'value length:', value?.length);
|
|
||||||
|
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
// In Electron, use localStorage instead of cookies
|
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
console.log('setCookie - stored in localStorage');
|
|
||||||
// Verify it was stored
|
|
||||||
const stored = localStorage.getItem(name);
|
|
||||||
console.log('setCookie - verification:', stored ? 'Successfully stored' : 'Failed to store');
|
|
||||||
} else {
|
} else {
|
||||||
// In browser, use cookies
|
|
||||||
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
||||||
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
|
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
|
||||||
console.log('setCookie - stored in cookies');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookie(name: string): string | undefined {
|
function getCookie(name: string): string | undefined {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
||||||
console.log('getCookie - isElectron:', isElectron);
|
|
||||||
|
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
// In Electron, get from localStorage
|
|
||||||
const token = localStorage.getItem(name) || undefined;
|
const token = localStorage.getItem(name) || undefined;
|
||||||
console.log('getCookie - localStorage result:', token ? 'Found' : 'Not found');
|
|
||||||
return token;
|
return token;
|
||||||
} else {
|
} else {
|
||||||
// In browser, get from cookies
|
|
||||||
const value = `; ${document.cookie}`;
|
const value = `; ${document.cookie}`;
|
||||||
const parts = value.split(`; ${name}=`);
|
const parts = value.split(`; ${name}=`);
|
||||||
const token = parts.length === 2 ? parts.pop()?.split(';').shift() : undefined;
|
const token = parts.length === 2 ? parts.pop()?.split(';').shift() : undefined;
|
||||||
console.log('getCookie - cookie result:', token ? 'Found' : 'Not found');
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,10 +191,8 @@ function createApiInstance(baseURL: string): AxiosInstance {
|
|||||||
|
|
||||||
instance.interceptors.request.use((config) => {
|
instance.interceptors.request.use((config) => {
|
||||||
const token = getCookie('jwt');
|
const token = getCookie('jwt');
|
||||||
console.log('Token from getCookie:', token ? 'Found' : 'Not found');
|
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
console.log('Authorization header set');
|
|
||||||
} else {
|
} else {
|
||||||
console.log('No token found, Authorization header not set');
|
console.log('No token found, Authorization header not set');
|
||||||
}
|
}
|
||||||
@@ -232,32 +216,24 @@ function createApiInstance(baseURL: string): AxiosInstance {
|
|||||||
// API INSTANCES
|
// API INSTANCES
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Check if running in Electron
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development' &&
|
const isDev = process.env.NODE_ENV === 'development' &&
|
||||||
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
||||||
|
|
||||||
// Get API host and port configuration
|
|
||||||
let apiHost = import.meta.env.VITE_API_HOST || 'localhost';
|
let apiHost = import.meta.env.VITE_API_HOST || 'localhost';
|
||||||
let apiPort = 8081;
|
let apiPort = 8081;
|
||||||
|
|
||||||
// In Electron, use fixed port since backend runs independently
|
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
// Backend runs independently, use default port
|
|
||||||
apiPort = 8081;
|
apiPort = 8081;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to get the correct API URL
|
|
||||||
function getApiUrl(path: string, defaultPort: number): string {
|
function getApiUrl(path: string, defaultPort: number): string {
|
||||||
if (isElectron) {
|
if (isElectron) {
|
||||||
// In Electron, always use localhost with dynamic port
|
return `http://127.0.0.1:${defaultPort}${path}`;
|
||||||
return `http://127.0.0.1:${apiPort}${path}`;
|
|
||||||
} else if (isDev) {
|
} else if (isDev) {
|
||||||
// In dev mode, use configured host
|
|
||||||
return `http://${apiHost}:${defaultPort}${path}`;
|
return `http://${apiHost}:${defaultPort}${path}`;
|
||||||
} else {
|
} else {
|
||||||
// In production web mode, use relative paths
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user