diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..6d6810e --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,22 @@ +# Use an official Nginx runtime as a parent image +FROM nginx:alpine + +# Set the working directory to the Nginx web root +WORKDIR /usr/share/nginx/html + +# Remove the default Nginx welcome page +RUN rm -f /usr/share/nginx/html/index.html + +# Copy the static assets from the frontend directory into the container +# This includes your HTML, CSS, JS, and assets folders. +COPY . . + +# Copy the custom Nginx configuration +# This replaces the default config with our version that includes the API proxy. +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Expose port 80 to allow traffic to the Nginx server +EXPOSE 80 + +# The command to start Nginx when the container launches +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/js/auth.js b/frontend/js/auth.js index e3f1071..1f664c7 100644 --- a/frontend/js/auth.js +++ b/frontend/js/auth.js @@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => { const password = document.getElementById('password').value; try { - const response = await fetch('http://localhost:5000/api/login', { + const response = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), diff --git a/frontend/js/dashboard.js b/frontend/js/dashboard.js index 2c184a5..0703b94 100644 --- a/frontend/js/dashboard.js +++ b/frontend/js/dashboard.js @@ -1,7 +1,6 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://localhost:5000"; - const API_BASE = "http://localhost:5000/api"; // Added for API calls + const API_BASE = "/api"; // Added for API calls // --- DOM ELEMENT REFERENCES --- const grid = document.getElementById('chambersGrid'); @@ -558,7 +557,7 @@ document.addEventListener('DOMContentLoaded', () => { }; const connectSocket = () => { - socket = io(SOCKET_URL); + socket = io(); // --- CHANGED: No longer sets status to "Online" on its own --- socket.on('connect', () => { diff --git a/frontend/js/logs.js b/frontend/js/logs.js index ec64195..ec2c1e8 100644 --- a/frontend/js/logs.js +++ b/frontend/js/logs.js @@ -1,7 +1,6 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://localhost:5000"; - const API_BASE = "http://localhost:5000/api"; + const API_BASE = "/api"; // --- DOM ELEMENT REFERENCES --- const stationNameEl = document.getElementById('station-name'); @@ -76,7 +75,7 @@ document.addEventListener('DOMContentLoaded', () => { } // --- SOCKET.IO CONNECTION --- - socket = io(SOCKET_URL); + socket = io(); socket.on('connect', () => { console.log("Connected to WebSocket for logs."); socket.emit('join_station_room', { station_id: selectedStation.id }); diff --git a/frontend/js/station_selection.js b/frontend/js/station_selection.js index cf8c7f8..cc7659f 100644 --- a/frontend/js/station_selection.js +++ b/frontend/js/station_selection.js @@ -86,7 +86,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- DATA FETCHING & STATUS POLLING --- const loadAndPollStations = async () => { try { - const response = await fetch('http://localhost:5000/api/stations'); + const response = await fetch('/api/stations'); if (!response.ok) throw new Error('Failed to fetch stations'); const stations = await response.json(); diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..e9fe8fd --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,32 @@ +server { + listen 80; + server_name localhost; + + # Root directory for static files + root /usr/share/nginx/html; + index index.html; + + # Serve static assets directly + location / { + try_files $uri $uri/ =404; + } + + # Proxy API requests to the backend service + # In Dokploy, you would set 'backend' to the name of your backend service. + location /api/ { + proxy_pass http://backend:5000/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Proxy WebSocket connections to the backend service + location /socket.io/ { + proxy_pass http://backend:5000/socket.io/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } +}