From 6607315658c460d091aeb287baba90d71ba6dc99 Mon Sep 17 00:00:00 2001 From: "Khoa.vo" Date: Wed, 24 Dec 2025 16:22:44 +0700 Subject: [PATCH] fix(api): Hardcode API URL for Android and add error toast --- backend/static/scripts/api.js | 5 ++--- backend/static/scripts/main.js | 1 + frontend/scripts/api.js | 5 ++--- frontend/scripts/main.js | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/static/scripts/api.js b/backend/static/scripts/api.js index 10e3cf0..37c3d3c 100644 --- a/backend/static/scripts/api.js +++ b/backend/static/scripts/api.js @@ -3,9 +3,8 @@ * Handles all communication with the backend */ -const API_BASE = window.location.origin.includes('localhost') || window.location.origin.includes('127.0.0.1') - ? '/api' - : 'https://nf.khoavo.myds.me/api'; +// Hardcode API_BASE to ensure Android App works correctly +const API_BASE = 'https://nf.khoavo.myds.me/api'; // In production, this should NOT be hardcoded if possible, or obfuscated. // Simple obfuscation for the secret key (should be improved in production) const _s = [121, 111, 117, 114, 45, 115, 117, 112, 101, 114, 45, 115, 101, 99, 114, 101, 116, 45, 107, 101, 121, 45, 99, 104, 97, 110, 103, 101, 45, 116, 104, 105, 115]; diff --git a/backend/static/scripts/main.js b/backend/static/scripts/main.js index ab849f3..01f4885 100644 --- a/backend/static/scripts/main.js +++ b/backend/static/scripts/main.js @@ -2314,6 +2314,7 @@ async function renderCategoryView(viewType) { } } catch (error) { console.error('Error rendering category view:', error); + showToast('Connection failed: ' + error.message, 'error'); elements.videoGrid.innerHTML = `
error diff --git a/frontend/scripts/api.js b/frontend/scripts/api.js index 10e3cf0..37c3d3c 100644 --- a/frontend/scripts/api.js +++ b/frontend/scripts/api.js @@ -3,9 +3,8 @@ * Handles all communication with the backend */ -const API_BASE = window.location.origin.includes('localhost') || window.location.origin.includes('127.0.0.1') - ? '/api' - : 'https://nf.khoavo.myds.me/api'; +// Hardcode API_BASE to ensure Android App works correctly +const API_BASE = 'https://nf.khoavo.myds.me/api'; // In production, this should NOT be hardcoded if possible, or obfuscated. // Simple obfuscation for the secret key (should be improved in production) const _s = [121, 111, 117, 114, 45, 115, 117, 112, 101, 114, 45, 115, 101, 99, 114, 101, 116, 45, 107, 101, 121, 45, 99, 104, 97, 110, 103, 101, 45, 116, 104, 105, 115]; diff --git a/frontend/scripts/main.js b/frontend/scripts/main.js index ab849f3..01f4885 100644 --- a/frontend/scripts/main.js +++ b/frontend/scripts/main.js @@ -2314,6 +2314,7 @@ async function renderCategoryView(viewType) { } } catch (error) { console.error('Error rendering category view:', error); + showToast('Connection failed: ' + error.message, 'error'); elements.videoGrid.innerHTML = `
error