From 6cc449847b52ae7917526422f5e4b8d04718e1fb Mon Sep 17 00:00:00 2001 From: Anyer Date: Fri, 13 Jun 2025 17:28:41 +0200 Subject: [PATCH] canviar baseUrl --- src/api.js | 4 ++-- src/pages/ChatbotEditor.tsx | 6 +++--- src/pages/MainPage.tsx | 4 ++-- src/services/flowService.ts | 24 ++++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/api.js b/src/api.js index 0b75f23..524517b 100644 --- a/src/api.js +++ b/src/api.js @@ -6,8 +6,8 @@ const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname.includes('192.168'); const baseURL = isLocalhost - ? 'http://127.0.0.1:8000/' - : 'http://187.33.149.121:8000/'; + ? 'http://127.0.0.1:8000/api/' + : '/api/'; const token = isLocalhost ? '5fc8db25bf14ab3c73c9ba1aee9c24041417eb1a' diff --git a/src/pages/ChatbotEditor.tsx b/src/pages/ChatbotEditor.tsx index c065456..359f594 100644 --- a/src/pages/ChatbotEditor.tsx +++ b/src/pages/ChatbotEditor.tsx @@ -14,7 +14,7 @@ const ChatbotEditor = () => { if (id) { const fetchBot = async () => { try { - const response = await api.get(`/api/botflows/${id}/`); + const response = await api.get(`botflows/${id}/`); setName(response.data.name); setDescription(response.data.description); } catch (error) { @@ -33,9 +33,9 @@ const ChatbotEditor = () => { try { if (id) { - await api.put(`/api/botflows/${id}/`, { name, description, phone_number: '000000000' }); + await api.put(`botflows/${id}/`, { name, description, phone_number: '000000000' }); } else { - const response = await api.post(`/api/botflows/`, { name, description, phone_number: '000000000' }); + const response = await api.post(`botflows/`, { name, description, phone_number: '000000000' }); return navigate(`/chatbot/${response.data.id}`); } diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index ab3d596..8bced4d 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -21,7 +21,7 @@ function Dashboard() { const confirmDelete = async () => { if (botToDelete) { try { - await api.delete(`/api/botflows/${botToDelete.id}/`); + await api.delete(`botflows/${botToDelete.id}/`); setChatbots((prev) => prev.filter((b) => b.id !== botToDelete.id)); } catch (err) { console.error('Error esborrant el bot:', err); @@ -41,7 +41,7 @@ function Dashboard() { useEffect(() => { const fetchBotflows = async () => { try { - const response = await api.get(`/api/botflows/`); + const response = await api.get(`botflows/`); setChatbots(response.data); } catch (error) { console.error('Error fetching botflows:', error); diff --git a/src/services/flowService.ts b/src/services/flowService.ts index 2d00e73..2422825 100644 --- a/src/services/flowService.ts +++ b/src/services/flowService.ts @@ -68,12 +68,12 @@ export const flowService = { } try { - const existingResponse = await api.get(`/api/botflows/${botflowId}/nodes/`); + const existingResponse = await api.get(`botflows/${botflowId}/nodes/`); const existingNodes = existingResponse.data || []; for (const node of existingNodes) { if (node.next_node) { - await api.put(`/api/nodes/${node.id}/`, { + await api.put(`nodes/${node.id}/`, { ...node, next_node: null }); @@ -81,7 +81,7 @@ export const flowService = { } try { - const listOptionsResponse = await api.get('/api/list-options/'); + const listOptionsResponse = await api.get('list-options/'); const listOptions = listOptionsResponse.data || []; const relevantOptions = listOptions.filter((option: any) => { @@ -90,14 +90,14 @@ export const flowService = { }); for (const option of relevantOptions) { - await api.delete(`/api/list-options/${option.id}/`); + await api.delete(`list-options/${option.id}/`); } } catch (listError) { console.warn("Error cleaning list options:", listError); } for (const node of existingNodes) { - await api.delete(`/api/nodes/${node.id}/`); + await api.delete(`nodes/${node.id}/`); } } catch (e) { console.warn("Error al limpiar nodos:", e); @@ -129,7 +129,7 @@ export const flowService = { try { for (let i = 1; i <= nodesData.length; i++) { try { - await api.delete(`/api/nodes/${i}/`); + await api.delete(`nodes/${i}/`); } catch (error) { // Ignore errors - node might not exist } @@ -140,7 +140,7 @@ export const flowService = { for (const nodeData of nodesData) { try { - await api.post(`/api/nodes/`, nodeData); + await api.post(`nodes/`, nodeData); } catch (nodeError: unknown) { const isAxiosError = (error: any): error is { response?: { data?: any; status?: number } } => { return error && typeof error === 'object' && 'response' in error; @@ -153,7 +153,7 @@ export const flowService = { if (nodeError.response?.status === 400) { try { - await api.put(`/api/nodes/${nodeData.id}/`, nodeData); + await api.put(`nodes/${nodeData.id}/`, nodeData); } catch (putError) { console.error(`PUT also failed for node ${nodeData.id}:`, putError); } @@ -165,7 +165,7 @@ export const flowService = { } try { - const allNodesResponse = await api.get(`/api/botflows/${botflowId}/nodes/`); + const allNodesResponse = await api.get(`botflows/${botflowId}/nodes/`); const allNodes = allNodesResponse.data; const nodesByPosition = new Map(); @@ -206,7 +206,7 @@ export const flowService = { } try { - await api.put(`/api/nodes/${backendSourceNode.id}/`, { + await api.put(`nodes/${backendSourceNode.id}/`, { ...backendSourceNode, next_node: backendTargetNode.id }); @@ -259,7 +259,7 @@ export const flowService = { } try { - await api.post('/api/list-options/', { + await api.post('list-options/', { node: backendNodeId, label: option, target_node: backendTargetNode.id @@ -286,7 +286,7 @@ export const flowService = { loadFlowNodes: async (botflowId: number) => { try { - const response = await api.get(`/api/botflows/${botflowId}/nodes/`); + const response = await api.get(`botflows/${botflowId}/nodes/`); return response.data; } catch (error) { console.error("Error cargando nodos:", error);