Files
snatchgame/client/server.js
josedario87 378febd8f3
All checks were successful
build-and-deploy / filter (push) Successful in 2s
build-and-deploy / build (push) Successful in 12s
build-and-deploy / deploy (push) Successful in 9s
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
2025-07-05 15:53:19 -06:00

49 lines
1.2 KiB
JavaScript

const express = require('express');
const path = require('path');
const dotenv = require('dotenv');
// Load environment variables
const ENV = process.env.NODE_ENV || 'development';
dotenv.config({ path: `.env.${ENV}` });
const app = express();
const PORT = process.env.PORT || 3000;
// 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) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Health check endpoint
app.get('/health', (req, res) => {
res.json({
status: 'healthy',
service: 'snatchgame-client',
environment: ENV,
serverUrl: process.env.SERVER_URL
});
});
// API endpoint to get environment config for client
app.get('/api/config', (req, res) => {
res.json({
serverUrl: process.env.SERVER_URL,
environment: ENV
});
});
app.listen(PORT, () => {
console.log(`
🎮 SnatchGame Client Server
📱 Environment: ${ENV}
🌐 Server URL: http://localhost:${PORT}
🔗 Game Server: ${process.env.SERVER_URL}
`);
});