Parametrisering av API endpoint

This commit is contained in:
Joakim Persson
2024-07-24 17:24:52 +02:00
parent 9a9b1388ce
commit feb7e61fd8
+8 -1
View File
@@ -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 }),