From feb7e61fd8ab2ce8d3147fecc01339bef8dc701c Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Wed, 24 Jul 2024 17:24:52 +0200 Subject: [PATCH] Parametrisering av API endpoint --- smartassist/src/frontend.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/smartassist/src/frontend.js b/smartassist/src/frontend.js index 22a336d..92c6c28 100644 --- a/smartassist/src/frontend.js +++ b/smartassist/src/frontend.js @@ -3,6 +3,12 @@ const chatbox = document.getElementById('chatbox'); const userInput = document.getElementById('userInput'); +// Get API endpoint for chat from environment variable +const apiEndpoint = process.env.BE_API_ENDPOINT || 'http://localhost:5005/api/chat'; // Default if not found +console.log("The API Endpoint is:", apiEndpoint); + + + // Define a function to send the user's message to the AI function sendMessage() { // Get the user's input message and trim any whitespace @@ -11,7 +17,8 @@ function sendMessage() { // Check if the message is not empty if (query !== '') { // Send a POST request to the /api/chat endpoint with the message - fetch('http://localhost:5005/api/chat', { + // fetch('http://localhost:5005/api/chat', { + fetch(apiEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }),