diff --git a/.env b/.env index 80733c3..ac060c0 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ VITE_basePath="/ketr.ketran" -NODE_CONFIG_ENV='production' \ No newline at end of file +NODE_CONFIG_ENV='production' +VITE_HMR_HOST=battle-linux.ketrenos.com +VITE_HMR_PROTOCOL=wss +VITE_HMR_PORT=3001 \ No newline at end of file diff --git a/client/index.html b/client/index.html new file mode 100755 index 0000000..cc6d6ca --- /dev/null +++ b/client/index.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + Peddlers of Ketran + + + +
+ + + + diff --git a/client/src/WebRTCStatus.tsx b/client/src/WebRTCStatus.tsx new file mode 100644 index 0000000..1b2616f --- /dev/null +++ b/client/src/WebRTCStatus.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { Box, CircularProgress, Typography } from '@mui/material'; + +interface WebRTCStatusProps { + isNegotiating: boolean; + connectionState?: string; +} + +const WebRTCStatus: React.FC = ({ + isNegotiating, + connectionState +}) => { + if (!isNegotiating && connectionState !== 'connecting') { + return null; + } + + return ( + + + + {isNegotiating ? 'Negotiating WebRTC...' : 'Connecting...'} + + + ); +}; + +export default WebRTCStatus; diff --git a/client/vite.config.js b/client/vite.config.js new file mode 100644 index 0000000..4c24904 --- /dev/null +++ b/client/vite.config.js @@ -0,0 +1,48 @@ +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +import fs from 'fs'; + +const httpsEnv = (process.env.HTTPS || '').toLowerCase(); +const useHttps = httpsEnv === 'true' || httpsEnv === '1'; +import tsconfigPaths from 'vite-tsconfig-paths' + + +// If custom cert paths are provided via env, use them; otherwise let Vite handle a self-signed cert when true. +const httpsOption = useHttps + ? (process.env.VITE_HTTPS_KEY && process.env.VITE_HTTPS_CERT + ? { + key: fs.readFileSync(process.env.VITE_HTTPS_KEY), + cert: fs.readFileSync(process.env.VITE_HTTPS_CERT) + } + : true) + : false; + +export default defineConfig({ + // Base public path when served in dev or production. Allow overriding + // via VITE_API_BASE (e.g. /ketr.ketran) so assets and manifest paths work. + base: '/', + plugins: [react(), tsconfigPaths()], + build: { + outDir: 'build', + }, + server: { + host: process.env.HOST || '0.0.0.0', + port: Number(process.env.PORT) || 3000, + https: httpsOption, + proxy: { + '/ketr.ketran/api': { + target: 'http://peddlers-server:8930', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/ketr.ketran/, '') + } + }, + // HMR options: allow overriding host/port/protocol from env so external + // browsers (accessing via a different hostname) can connect to the dev + // server's websocket. See https://vite.dev/config/server-options.html#server-hmr + hmr: { + port: process.env.VITE_HMR_PORT || 3001, + host: process.env.VITE_HMR_HOST || 'localhost', + protocol: process.env.VITE_HMR_PROTOCOL || 'ws' + } + } +}); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0664f12..ea70f09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: context: . dockerfile: Dockerfile restart: always + env_file: + - .env ports: - 8930:8930 volumes: @@ -53,7 +55,12 @@ services: # a certificate for the external hostname (e.g. battle-linux.ketrenos.com). - VITE_HTTPS_KEY=/certs/battle.key - VITE_HTTPS_CERT=/certs/battle.crt - command: ["bash", "-c", "cd /client && npm install --legacy-peer-deps --silent --no-audit --no-fund && npm start"] + env_file: + - .env + # Install deps then run vite directly to avoid using the npm wrapper which + # was receiving SIGTERM in the container and making the service appear to + # restart repeatedly. + command: ["bash", "-c", "cd /client && npm install --legacy-peer-deps --silent --no-audit --no-fund && ./node_modules/.bin/vite --host"] networks: - peddlers-network