Fix connection
This commit is contained in:
1 parent
4ad665cac0
commit
b8a847c210
12 files changed
+56
-18
No files matched your search
@@ -5,6 +5,11 @@ COPY package*.json ./
|
|||||||
# On installe les dépendances
|
# On installe les dépendances
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
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)
|
# On lance le build (en ignorant les erreurs TypeScript si tu as modifié le package.json comme convenu)
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -41,7 +41,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
|
|||||||
|
|
||||||
const fetchConversations = async () => {
|
const fetchConversations = async () => {
|
||||||
try {
|
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();
|
const data = await res.json();
|
||||||
setConversations(data);
|
setConversations(data);
|
||||||
// Si aucune conv n'est sélectionnée, prendre la plus récente
|
// 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) => {
|
const fetchMessages = async (id: number) => {
|
||||||
try {
|
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();
|
const data = await res.json();
|
||||||
setMessages(data.messages || []);
|
setMessages(data.messages || []);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -66,7 +66,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
|
|||||||
const startNewChat = async () => {
|
const startNewChat = async () => {
|
||||||
try {
|
try {
|
||||||
const title = currentService ? `Analyse ${currentService.name}` : "Nouvelle discussion";
|
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',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
@@ -86,7 +86,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
|
|||||||
const deleteConversation = async (e: React.MouseEvent, id: number) => {
|
const deleteConversation = async (e: React.MouseEvent, id: number) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
try {
|
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',
|
method: 'DELETE',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
@@ -127,7 +127,7 @@ export default function AIChatSidebar({ isOpen, onClose, currentService }: AICha
|
|||||||
abortControllerRef.current = abortController;
|
abortControllerRef.current = abortController;
|
||||||
|
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function AddServiceModal({ onClose, onAdded }: { onClose: () => v
|
|||||||
setFormData(prev => ({ ...prev, pathOrContainerId: '' }));
|
setFormData(prev => ({ ...prev, pathOrContainerId: '' }));
|
||||||
try {
|
try {
|
||||||
const endpoint = formData.type === 'docker' ? '/api/docker/containers' : '/api/os/services';
|
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'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -35,7 +35,7 @@ export default function AddServiceModal({ onClose, onAdded }: { onClose: () => v
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await fetch('http://localhost:3001/api/services', {
|
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/services`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default function LogTerminal({ service, initialLogs = [] }: {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socketRef.current) {
|
if (!socketRef.current) {
|
||||||
socketRef.current = io('http://localhost:3001', {
|
socketRef.current = io(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}`, {
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default function SettingsModal({ onClose }: { onClose: () => void }) {
|
|||||||
const [saved, setSaved] = useState(false);
|
const [saved, setSaved] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch('http://localhost:3001/api/settings', {
|
fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
@@ -33,7 +33,7 @@ export default function SettingsModal({ onClose }: { onClose: () => void }) {
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await fetch('http://localhost:3001/api/settings', {
|
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkSession = async () => {
|
const checkSession = async () => {
|
||||||
try {
|
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'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -49,7 +49,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
|
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default function HomeView() {
|
|||||||
|
|
||||||
const fetchServices = async () => {
|
const fetchServices = async () => {
|
||||||
try {
|
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'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function LoginView() {
|
|||||||
setError('');
|
setError('');
|
||||||
|
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ export default function ServiceView() {
|
|||||||
const fetchServiceAndLogs = async () => {
|
const fetchServiceAndLogs = async () => {
|
||||||
try {
|
try {
|
||||||
const [svcRes, logsRes] = await Promise.all([
|
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'
|
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'
|
credentials: 'include'
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
@@ -76,7 +76,7 @@ export default function ServiceView() {
|
|||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
try {
|
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',
|
method: 'DELETE',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export default function SignupView() {
|
|||||||
setError('');
|
setError('');
|
||||||
|
|
||||||
try {
|
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',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
|||||||
Reference in new issue
Block a user