diff --git a/Frontend/.env.example b/Frontend/.env.example new file mode 100644 index 0000000..b47c776 --- /dev/null +++ b/Frontend/.env.example @@ -0,0 +1,7 @@ +# Monaco Frontend Environment Variables + +# Backend API URL (Monaco code execution server) +VITE_API_URL=http://localhost:8080 + +# Faculty API URL (Faculty/Student management backend) +VITE_FACULTY_API_URL=http://localhost:5000/api diff --git a/Frontend/src/components/CodeChallenge.jsx b/Frontend/src/components/CodeChallenge.jsx index c4c3b8c..107a17d 100644 --- a/Frontend/src/components/CodeChallenge.jsx +++ b/Frontend/src/components/CodeChallenge.jsx @@ -339,7 +339,10 @@ int main() { } console.log('Creating new WebSocket connection'); - const wsUrl = `ws://localhost:8080/api/ws/terminal/${id}`; + const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8080'; + const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + const wsBaseUrl = apiUrl.replace(/^https?:\/\//, ''); + const wsUrl = `${wsProtocol}//${wsBaseUrl}/api/ws/terminal/${id}`; const socket = new WebSocket(wsUrl); socket.onopen = () => { @@ -515,7 +518,8 @@ int main() { try { // Submit code to the backend - const response = await fetch('http://localhost:8080/api/submit', { + const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8080'; + const response = await fetch(`${apiUrl}/api/submit`, { method: 'POST', headers: { 'Content-Type': 'application/json',