From abc15efabd28df65df33dab07c78c2c8118a3b58 Mon Sep 17 00:00:00 2001 From: ishikabhoyar Date: Fri, 31 Oct 2025 15:12:58 +0530 Subject: [PATCH] refactor API URL handling in TestList and AuthContext components --- Frontend/src/components/TestList.jsx | 9 ++++++--- Frontend/src/contexts/AuthContext.jsx | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Frontend/src/components/TestList.jsx b/Frontend/src/components/TestList.jsx index 458ef7d..81c035f 100644 --- a/Frontend/src/components/TestList.jsx +++ b/Frontend/src/components/TestList.jsx @@ -21,7 +21,8 @@ const TestList = () => { const fetchTests = async () => { try { console.log('Fetching tests with token:', token?.substring(0, 50) + '...'); - const response = await fetch('http://localhost:5000/api/students/tests', { + const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api'; + const response = await fetch(`${API_URL}/students/tests`, { headers: { 'Authorization': `Bearer ${token}` } @@ -57,7 +58,8 @@ const TestList = () => { const handleStartTest = async (test) => { try { - const response = await fetch(`http://localhost:5000/api/students/tests/${test.id}/questions`, { + const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api'; + const response = await fetch(`${API_URL}/students/tests/${test.id}/questions`, { headers: { 'Authorization': `Bearer ${token}` } @@ -83,7 +85,8 @@ const TestList = () => { if (!selectedTest || !password) return; try { - const response = await fetch(`http://localhost:5000/api/students/tests/${selectedTest.id}/verify-password`, { + const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api'; + const response = await fetch(`${API_URL}/students/tests/${selectedTest.id}/verify-password`, { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, diff --git a/Frontend/src/contexts/AuthContext.jsx b/Frontend/src/contexts/AuthContext.jsx index 8538a22..805b14e 100644 --- a/Frontend/src/contexts/AuthContext.jsx +++ b/Frontend/src/contexts/AuthContext.jsx @@ -41,7 +41,8 @@ export const AuthProvider = ({ children }) => { // For Google OAuth login if (googleToken && userInfo) { // Exchange Google token for our JWT - const response = await fetch('http://localhost:5000/api/students/login', { + const API_URL = import.meta.env.VITE_FACULTY_API_URL || 'http://localhost:5000/api'; + const response = await fetch(`${API_URL}/students/login`, { method: 'POST', headers: { 'Content-Type': 'application/json',