Update AppImage

This commit is contained in:
MacRimi
2025-12-06 20:27:00 +01:00
parent d30c836d04
commit 05a2eca9a7
3 changed files with 185 additions and 253 deletions

View File

@@ -19,21 +19,28 @@ export const API_PORT = process.env.NEXT_PUBLIC_API_PORT || "8008"
*/
export function getApiBaseUrl(): string {
if (typeof window === "undefined") {
console.log("[v0] getApiBaseUrl: Running on server (SSR)")
return ""
}
const { protocol, hostname, port } = window.location
console.log("[v0] getApiBaseUrl - protocol:", protocol, "hostname:", hostname, "port:", port)
// If accessing via standard ports (80/443) or no port, assume we're behind a proxy
// In this case, use relative URLs so the proxy handles routing
const isStandardPort = port === "" || port === "80" || port === "443"
console.log("[v0] getApiBaseUrl - isStandardPort:", isStandardPort)
if (isStandardPort) {
// Behind a proxy - use relative URL
console.log("[v0] getApiBaseUrl: Detected proxy access, using relative URLs")
return ""
} else {
// Direct access - use explicit API port
const baseUrl = `${protocol}//${hostname}:${API_PORT}`
console.log("[v0] getApiBaseUrl: Direct access detected, using:", baseUrl)
return baseUrl
}
}
@@ -62,7 +69,12 @@ export function getAuthToken(): string | null {
if (typeof window === "undefined") {
return null
}
return localStorage.getItem("proxmenux-auth-token")
const token = localStorage.getItem("proxmenux-auth-token")
console.log(
"[v0] getAuthToken called:",
token ? `Token found (length: ${token.length})` : "No token found in localStorage",
)
return token
}
/**
@@ -84,6 +96,9 @@ export async function fetchApi<T>(endpoint: string, options?: RequestInit): Prom
if (token) {
headers["Authorization"] = `Bearer ${token}`
console.log("[v0] fetchApi:", endpoint, "- Authorization header ADDED")
} else {
console.log("[v0] fetchApi:", endpoint, "- NO TOKEN - Request will fail if endpoint is protected")
}
try {
@@ -93,8 +108,11 @@ export async function fetchApi<T>(endpoint: string, options?: RequestInit): Prom
cache: "no-store",
})
console.log("[v0] fetchApi:", endpoint, "- Response status:", response.status)
if (!response.ok) {
if (response.status === 401) {
console.error("[v0] fetchApi: 401 UNAUTHORIZED -", endpoint, "- Token present:", !!token)
throw new Error(`Unauthorized: ${endpoint}`)
}
throw new Error(`API request failed: ${response.status} ${response.statusText}`)
@@ -102,7 +120,7 @@ export async function fetchApi<T>(endpoint: string, options?: RequestInit): Prom
return response.json()
} catch (error) {
console.error("API fetch error for", endpoint, ":", error)
console.error("[v0] fetchApi error for", endpoint, ":", error)
throw error
}
}