Testar vidare...
This commit is contained in:
@@ -5,71 +5,6 @@ const userInput = document.getElementById('userInput');
|
|||||||
|
|
||||||
// Get API endpoint for chat from environment variable
|
// Get API endpoint for chat from environment variable
|
||||||
|
|
||||||
// const apiEndpoint = process.env.BE_API_ENDPOINT || 'http://localhost:5005/api/chat'; // Default if not found
|
|
||||||
// const apiEndpoint = '<%= api_endpoint %>'; // Templating syntax (Jinja2)
|
|
||||||
// const iframe = document.getElementById('client-frame');
|
|
||||||
// const apiEndpoint = iframe.getAttribute('data-api-endpoint');
|
|
||||||
// console.log("frontend.js - the API Endpoint is:", apiEndpoint);
|
|
||||||
|
|
||||||
// document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// const iframe = document.getElementById('client-frame');
|
|
||||||
// const iframeContentUrl = iframe.srcdoc;
|
|
||||||
|
|
||||||
// // Extract the query parameter 'apiEndpoint' from the URL
|
|
||||||
// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]);
|
|
||||||
// const apiEndpoint = urlParams.get('apiEndpoint');
|
|
||||||
|
|
||||||
// console.log("frontend.js - The API Endpoint is:", apiEndpoint);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// setTimeout(() => {
|
|
||||||
// const iframe = document.getElementById('client-frame');
|
|
||||||
// if (iframe) {
|
|
||||||
// const iframeContentUrl = iframe.srcdoc;
|
|
||||||
// // Extract the query parameter 'apiEndpoint' from the URL
|
|
||||||
// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]);
|
|
||||||
// const apiEndpoint = urlParams.get('apiEndpoint'); } else {
|
|
||||||
// console.error("Error: iframe element not found.");
|
|
||||||
// }
|
|
||||||
// }, 100); // Adjust this delay (in milliseconds) if needed
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const observer = new MutationObserver(() => {
|
|
||||||
// const iframe = document.getElementById('client-frame');
|
|
||||||
// if (iframe) {
|
|
||||||
// console.log("iframe DO exist")
|
|
||||||
// if (iframe.srcdoc) {
|
|
||||||
// console.log("srcdoc exist")
|
|
||||||
// // Extract the query parameter 'apiEndpoint' from the URL
|
|
||||||
// const urlParams = new URLSearchParams(iframe.srcdoc.split('?')[1]);
|
|
||||||
// const apiEndpoint = urlParams.get('apiEndpoint');
|
|
||||||
// console.log("frontend.js - The API Endpoint is:", apiEndpoint);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// console.error("Error: iframe.srcdoc not found.");
|
|
||||||
// observer.disconnect(); // Stop observing once you've extracted the data
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// console.error("Error: iframe DOES NOT exist.");
|
|
||||||
// observer.disconnect(); // Stop observing once you've extracted the data
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// if (iframe && iframe.srcdoc) { // Check if iframe exists and srcdoc is populated
|
|
||||||
// const iframeContentUrl = iframe.srcdoc;
|
|
||||||
// // Extract the query parameter 'apiEndpoint' from the URL
|
|
||||||
// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]);
|
|
||||||
// const apiEndpoint = urlParams.get('apiEndpoint');
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// console.error("Error: iframe element not found.");
|
|
||||||
// observer.disconnect(); // Stop observing once you've extracted the data
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// observer.observe(document.body, { childList: true, subtree: true });
|
|
||||||
|
|
||||||
// Handle resize events
|
// Handle resize events
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
@@ -128,18 +63,18 @@ function renderMessage(text, className) {
|
|||||||
|
|
||||||
|
|
||||||
function handleIframeLoad() {
|
function handleIframeLoad() {
|
||||||
const iframe = document.getElementById('client-frame');
|
const clientFrame = document.getElementById('client-frame');
|
||||||
|
|
||||||
if (iframe) { // Check if the iframe exists
|
if (clientFrame) { // Check if the iframe exists
|
||||||
|
|
||||||
const apiEndpoint = iframe.getAttribute('data-api-endpoint') || iframe.srcdoc.split('?')[1].split('=')[1];
|
const apiEndpoint = clientFrame.getAttribute('data-api-endpoint') || clientFrame.srcdoc.split('?')[1].split('=')[1];
|
||||||
console.log("The API Endpoint is:", apiEndpoint);
|
console.log("The API Endpoint is:", apiEndpoint);
|
||||||
|
|
||||||
// Now you can use this 'apiEndpoint' for communication
|
// Now you can use this 'apiEndpoint' for communication
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setTimeout(handleIframeLoad, 200); // Retry in a short while if iframe not found yet
|
setTimeout(handleIframeLoad, 200); // Retry in a short while if iframe not found yet
|
||||||
console.log("iframe not found yet");
|
console.log("The iframe with id client-frame not found yet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user