From 378febd8f38cf49d758c1406e30c66cb2a6ac79e Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 5 Jul 2025 15:53:19 -0600 Subject: [PATCH] fix: Correct environment variables and MIME types for production - Change VITE_SERVER_URL to SERVER_URL in docker-compose - Add dist directory serving for built assets - Configure Express to serve JS modules with correct MIME type - Fix undefined Game Server in containers --- admin/server.js | 6 +++++- client/server.js | 6 +++++- docker-compose.yml | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/admin/server.js b/admin/server.js index df7a0ab..26dd8e5 100644 --- a/admin/server.js +++ b/admin/server.js @@ -153,8 +153,12 @@ app.post('/api/admin/cancel-game', async (req, res) => { } }); -// Serve static files from current directory (AFTER API routes) +// Configure MIME types for modules +express.static.mime.define({'application/javascript': ['js', 'mjs']}); + +// Serve static files from current directory and dist (AFTER API routes) app.use(express.static('.')); +app.use(express.static('dist')); // Serve main HTML file for SPA routes app.get('*', (req, res) => { diff --git a/client/server.js b/client/server.js index e242401..62b7688 100644 --- a/client/server.js +++ b/client/server.js @@ -9,8 +9,12 @@ dotenv.config({ path: `.env.${ENV}` }); const app = express(); const PORT = process.env.PORT || 3000; -// Serve static files from current directory +// Configure MIME types for modules +express.static.mime.define({'application/javascript': ['js', 'mjs']}); + +// Serve static files from current directory and dist app.use(express.static('.')); +app.use(express.static('dist')); // Serve main HTML file app.get('/', (req, res) => { diff --git a/docker-compose.yml b/docker-compose.yml index 5694b23..1f456db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: environment: - NODE_ENV=production - PORT=3000 - - VITE_SERVER_URL=http://snatchgame-server:2567 + - SERVER_URL=http://snatchgame-server:2567 depends_on: - snatchgame-server networks: @@ -51,7 +51,7 @@ services: environment: - NODE_ENV=production - PORT=3001 - - VITE_SERVER_URL=http://snatchgame-server:2567 + - SERVER_URL=http://snatchgame-server:2567 depends_on: - snatchgame-server networks: