Fix connection

This commit is contained in:
Orionis312050 committed 2026-04-16 18:23:16 +02:00
1 parent 4ad665cac0
commit b8a847c210
12 files changed
+56 -18

No files matched your search

+1
View File
@@ -0,0 +1 @@
VITE_API_URL=http://localhost:3001
+5
View File
@@ -5,6 +5,11 @@ COPY package*.json ./
# On installe les dépendances
RUN npm ci
COPY . .
# On récupère la variable VITE_API_URL injectée par Coolify pendant le build
ARG VITE_API_URL
ENV VITE_API_URL=$VITE_API_URL
# On lance le build (en ignorant les erreurs TypeScript si tu as modifié le package.json comme convenu)
RUN npm run build
+32
View File
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');
const dir = 'c:\\Users\\Goura\\AntigravityProjects\\LogManager\\frontend\\src';
function replaceInFile(filePath) {
let content = fs.readFileSync(filePath, 'utf8');
let original = content;
// Pattern 1: single quotes
content = content.replace(/'http:\/\/localhost:3001([^']*)'/g, "`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}$1`");
// Pattern 2: backticks (template literals)
// Avoid double injecting if already replaced
content = content.replace(/`http:\/\/localhost:3001([^`]*)`/g, "`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}$1`");
if (content !== original) {
fs.writeFileSync(filePath, content);
console.log("Updated", filePath);
}
}
function walk(dir) {
const list = fs.readdirSync(dir);
for (let file of list) {
file = path.resolve(dir, file);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) walk(file);
else if (file.endsWith('.ts') || file.endsWith('.tsx')) replaceInFile(file);
}
}
walk(dir);
+5 -5
View File
@@ -41,7 +41,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
const fetchConversations = async () => {
try {
const res = await fetch('http://localhost:3001/api/ai/conversations', { credentials: 'include' });
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/ai/conversations`, { credentials: 'include' });
const data = await res.json();
setConversations(data);
// Si aucune conv n'est sélectionnée, prendre la plus récente
@@ -55,7 +55,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
const fetchMessages = async (id: number) => {
try {
const res = await fetch(`http://localhost:3001/api/ai/conversations/${id}`, { credentials: 'include' });
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/ai/conversations/${id}`, { credentials: 'include' });
const data = await res.json();
setMessages(data.messages || []);
} catch (err) {
@@ -66,7 +66,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
const startNewChat = async () => {
try {
const title = currentService ? `Analyse ${currentService.name}` : "Nouvelle discussion";
const res = await fetch('http://localhost:3001/api/ai/conversations', {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/ai/conversations`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
@@ -86,7 +86,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
const deleteConversation = async (e: React.MouseEvent, id: number) => {
e.stopPropagation();
try {
await fetch(`http://localhost:3001/api/ai/conversations/${id}`, {
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/ai/conversations/${id}`, {
method: 'DELETE',
credentials: 'include'
});
@@ -127,7 +127,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
abortControllerRef.current = abortController;
try {
const response = await fetch('http://localhost:3001/api/ai/chat-stream', {
const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/ai/chat-stream`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
+2 -2
View File
@@ -18,7 +18,7 @@ export default function AddServiceModal({ onClose, onAdded }: { onClose: () => v
setFormData(prev => ({ ...prev, pathOrContainerId: '' }));
try {
const endpoint = formData.type === 'docker' ? '/api/docker/containers' : '/api/os/services';
const res = await fetch(`http://localhost:3001${endpoint}`, {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}${endpoint}`, {
credentials: 'include'
});
const data = await res.json();
@@ -35,7 +35,7 @@ export default function AddServiceModal({ onClose, onAdded }: { onClose: () => v
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await fetch('http://localhost:3001/api/services', {
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
+1 -1
View File
@@ -20,7 +20,7 @@ export default function LogTerminal({ service, initialLogs = [] }: {
useEffect(() => {
if (!socketRef.current) {
socketRef.current = io('http://localhost:3001', {
socketRef.current = io(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}`, {
withCredentials: true
});
}
+2 -2
View File
@@ -12,7 +12,7 @@ export default function SettingsModal({ onClose }: { onClose: () => void }) {
const [saved, setSaved] = useState(false);
useEffect(() => {
fetch('http://localhost:3001/api/settings', {
fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
credentials: 'include'
})
.then(res => res.json())
@@ -33,7 +33,7 @@ export default function SettingsModal({ onClose }: { onClose: () => void }) {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await fetch('http://localhost:3001/api/settings', {
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
+2 -2
View File
@@ -23,7 +23,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
useEffect(() => {
const checkSession = async () => {
try {
const res = await fetch('http://localhost:3001/api/auth/me', {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/auth/me`, {
credentials: 'include'
});
if (res.ok) {
@@ -49,7 +49,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const logout = async () => {
try {
await fetch('http://localhost:3001/api/auth/logout', {
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/auth/logout`, {
method: 'POST',
credentials: 'include'
});
+1 -1
View File
@@ -12,7 +12,7 @@ export default function HomeView() {
const fetchServices = async () => {
try {
const res = await fetch('http://localhost:3001/api/services', {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services`, {
credentials: 'include'
});
const data = await res.json();
+1 -1
View File
@@ -18,7 +18,7 @@ export default function LoginView() {
setError('');
try {
const res = await fetch('http://localhost:3001/api/auth/login', {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
+3 -3
View File
@@ -36,10 +36,10 @@ export default function ServiceView() {
const fetchServiceAndLogs = async () => {
try {
const [svcRes, logsRes] = await Promise.all([
fetch(`http://localhost:3001/api/services`, {
fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services`, {
credentials: 'include'
}),
fetch(`http://localhost:3001/api/services/${id}/logs`, {
fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services/${id}/logs`, {
credentials: 'include'
})
]);
@@ -76,7 +76,7 @@ export default function ServiceView() {
const handleDelete = async () => {
try {
await fetch(`http://localhost:3001/api/services/${id}`, {
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services/${id}`, {
method: 'DELETE',
credentials: 'include'
});
+1 -1
View File
@@ -24,7 +24,7 @@ export default function SignupView() {
setError('');
try {
const res = await fetch('http://localhost:3001/api/auth/register', {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/auth/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',