diff --git a/client/.env.example b/client/.env.example new file mode 100644 index 0000000..2e947e9 --- /dev/null +++ b/client/.env.example @@ -0,0 +1,11 @@ +# Client Environment Configuration + +# Base path for the application (used for deployment in subdirectories) +# Default: '/drones' in production, '' in development +# Example: VITE_BASE_PATH=/my-custom-path +# VITE_BASE_PATH= + +# API URL override (if API is hosted on different domain/port) +# Default: auto-detected based on environment +# Example: VITE_API_URL=https://api.example.com/api +# VITE_API_URL= diff --git a/client/src/App.jsx b/client/src/App.jsx index 5dde829..ce7b55e 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -3,6 +3,7 @@ import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; import { Toaster } from 'react-hot-toast'; import { AuthProvider } from './contexts/AuthContext'; import { SocketProvider } from './contexts/SocketContext'; +import APP_CONFIG from './config/app'; import Layout from './components/Layout'; import Dashboard from './pages/Dashboard'; import MapView from './pages/MapView'; @@ -17,7 +18,7 @@ function App() { return ( - +
{ useEffect(() => { if (isAuthenticated) { // Initialize socket connection - const newSocket = io(process.env.NODE_ENV === 'production' + const newSocket = io(APP_CONFIG.isProduction ? window.location.origin : 'http://localhost:3001', { - path: process.env.NODE_ENV === 'production' ? '/drones/socket.io/' : '/socket.io/' + path: APP_CONFIG.isProduction ? `${APP_CONFIG.basePath}/socket.io/` : '/socket.io/' }); newSocket.on('connect', () => { diff --git a/client/src/services/api.js b/client/src/services/api.js index 14a0282..0801172 100644 --- a/client/src/services/api.js +++ b/client/src/services/api.js @@ -1,4 +1,5 @@ import axios from 'axios'; +import APP_CONFIG from '../config/app'; // Determine API base URL based on environment const getApiBaseUrl = () => { @@ -12,8 +13,8 @@ const getApiBaseUrl = () => { return 'http://localhost:3002/api'; } - // Otherwise, use relative URL (same domain) - return '/drones/api'; + // Otherwise, use the configured base path + /api + return `${APP_CONFIG.basePath}/api`; }; const API_BASE_URL = getApiBaseUrl(); diff --git a/client/vite.config.js b/client/vite.config.js index 3630376..e2f8ef0 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -1,9 +1,14 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +// Application base path configuration +// Can be overridden with VITE_BASE_PATH environment variable +// This should match the base path used in nginx/reverse proxy configuration +const BASE_PATH = process.env.VITE_BASE_PATH || (process.env.NODE_ENV === 'production' ? '/drones/' : '/') + export default defineConfig({ plugins: [react()], - base: process.env.NODE_ENV === 'production' ? '/drones/' : '/', + base: BASE_PATH, // Used for asset paths and routing server: { port: 3000, proxy: { diff --git a/server/routes/devices.js b/server/routes/devices.js new file mode 100644 index 0000000..e69de29 diff --git a/server/routes/droneDetection.js b/server/routes/droneDetection.js new file mode 100644 index 0000000..e69de29 diff --git a/server/routes/heartbeat.js b/server/routes/heartbeat.js new file mode 100644 index 0000000..e69de29