refactor WebSocket and fetch API URLs to use environment variables for better configuration
This commit is contained in:
7
Frontend/.env.example
Normal file
7
Frontend/.env.example
Normal file
@@ -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
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user