cleaup env

This commit is contained in:
2025-09-17 09:52:47 +02:00
parent be3a9002b3
commit 2912b99aa1
10 changed files with 105 additions and 38 deletions

View File

@@ -16,8 +16,21 @@ export const viewport: Viewport = {
initialScale: 1,
}
// Function to determine the base URL with proper protocol
const getBaseUrl = () => {
// In production, we need to detect if we're behind HTTPS
if (typeof window !== 'undefined') {
const protocol = window.location.protocol === 'https:' ? 'https' : 'http'
const host = process.env.NEXT_PUBLIC_BASE_URL || window.location.hostname
return `${protocol}://${host}`
}
// For build time/server side, default to HTTP for dev, HTTPS for production
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'
return `${protocol}://${process.env.NEXT_PUBLIC_BASE_URL || 'localhost'}`
}
export const metadata: Metadata = {
metadataBase: new URL(`http://${process.env.NEXT_PUBLIC_BASE_URL || 'localhost'}`),
metadataBase: new URL(getBaseUrl()),
title: 'Enclava Platform',
description: 'Secure AI processing platform with plugin-based architecture and confidential computing',
keywords: ['AI', 'Enclava', 'Confidential Computing', 'LLM', 'TEE'],
@@ -26,7 +39,7 @@ export const metadata: Metadata = {
openGraph: {
type: 'website',
locale: 'en_US',
url: `http://${process.env.NEXT_PUBLIC_BASE_URL || 'localhost'}`,
url: getBaseUrl(),
title: 'Enclava Platform',
description: 'Secure AI processing platform with plugin-based architecture and confidential computing',
siteName: 'Enclava',

View File

@@ -91,8 +91,9 @@ export function DocumentUpload({ collections, selectedCollection, onDocumentUplo
updateProgress(60)
await uploadFile(
'/api-internal/v1/rag/documents',
uploadingFile.file,
'/api-internal/v1/rag/documents',
(progress) => updateProgress(progress),
{ collection_id: targetCollection }
)

View File

@@ -18,6 +18,16 @@ import {
import { User, Settings, Lock, LogOut, ChevronDown } from "lucide-react"
import { useState } from "react"
// Helper function to get API URL with proper protocol
const getApiUrl = () => {
if (typeof window !== 'undefined') {
const protocol = window.location.protocol.slice(0, -1) // Remove ':' from 'https:'
const host = window.location.hostname
return `${protocol}://${host}`
}
return `http://${process.env.NEXT_PUBLIC_BASE_URL || 'localhost'}`
}
export function UserMenu() {
const { user, logout } = useAuth()
const { toast } = useToast()
@@ -62,7 +72,7 @@ export function UserMenu() {
throw new Error('Authentication required')
}
const response = await fetch('/api-internal/v1/auth/change-password', {
const response = await fetch(`${getApiUrl()}/api-internal/v1/auth/change-password`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@@ -4,6 +4,16 @@ import { createContext, useContext, useState, useEffect, ReactNode } from "react
import { useRouter } from "next/navigation"
import { tokenManager } from "@/lib/token-manager"
// Helper function to get API URL with proper protocol
const getApiUrl = () => {
if (typeof window !== 'undefined') {
const protocol = window.location.protocol.slice(0, -1) // Remove ':' from 'https:'
const host = window.location.hostname
return `${protocol}://${host}`
}
return `http://${process.env.NEXT_PUBLIC_BASE_URL || 'localhost'}`
}
interface User {
id: string
email: string
@@ -84,7 +94,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const token = await tokenManager.getAccessToken()
if (!token) return
const response = await fetch('/api-internal/v1/auth/me', {
const response = await fetch(`${getApiUrl()}/api-internal/v1/auth/me`, {
headers: {
'Authorization': `Bearer ${token}`,
},
@@ -114,7 +124,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
setIsLoading(true)
try {
const response = await fetch('/api-internal/v1/auth/login', {
const response = await fetch(`${getApiUrl()}/api-internal/v1/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@@ -1,10 +1,23 @@
import axios from 'axios';
import Cookies from 'js-cookie';
const API_BASE_URL = process.env.NEXT_PUBLIC_BASE_URL || '';
// Dynamic base URL with protocol detection
const getApiBaseUrl = (): string => {
if (typeof window !== 'undefined') {
// Client-side: use the same protocol as the current page
const protocol = window.location.protocol.slice(0, -1); // Remove ':' from 'https:'
const host = window.location.hostname;
return `${protocol}://${host}`;
}
// Server-side: use environment variable or default to localhost
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'localhost';
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
return `${protocol}://${baseUrl}`;
};
const axiosInstance = axios.create({
baseURL: API_BASE_URL,
baseURL: getApiBaseUrl(),
headers: {
'Content-Type': 'application/json',
},
@@ -36,7 +49,7 @@ axiosInstance.interceptors.response.use(
try {
const refreshToken = Cookies.get('refresh_token');
if (refreshToken) {
const response = await axios.post(`${API_BASE_URL}/api/auth/refresh`, {
const response = await axios.post(`${getApiBaseUrl()}/api/auth/refresh`, {
refresh_token: refreshToken,
});

View File

@@ -76,12 +76,20 @@ export const downloadFileFromData = (
export const uploadFile = async (
file: File,
url: string,
onProgress?: (progress: number) => void
onProgress?: (progress: number) => void,
additionalData?: Record<string, any>
): Promise<any> => {
try {
const formData = new FormData();
formData.append('file', file);
// Add additional form data if provided
if (additionalData) {
Object.entries(additionalData).forEach(([key, value]) => {
formData.append(key, value);
});
}
const xhr = new XMLHttpRequest();
return new Promise((resolve, reject) => {