fix: Permitir múltiples orígenes CORS y añadir logs de admin
- Permitir conexiones desde localhost, 127.0.0.1 y la IP de red local - Corregir error de compilación de 'pg' reconstruyendo la imagen - Añadir logs para depuración del dashboard de administración
This commit is contained in:
@@ -28,3 +28,5 @@
|
||||
"typescript": "^5.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,15 +16,28 @@ initDb();
|
||||
const app = express();
|
||||
const port = process.env.PORT || 4000;
|
||||
|
||||
const allowedOrigins = [
|
||||
process.env.CORS_ORIGIN || "http://localhost:3000",
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
"http://192.168.1.131:3000"
|
||||
];
|
||||
|
||||
app.use(cors({
|
||||
origin: process.env.CORS_ORIGIN || "http://localhost:3000",
|
||||
origin: (origin, callback) => {
|
||||
if (!origin || allowedOrigins.includes(origin)) {
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
},
|
||||
methods: ["GET", "POST"]
|
||||
}));
|
||||
|
||||
const server = http.createServer(app);
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: process.env.CORS_ORIGIN || "http://localhost:3000",
|
||||
origin: allowedOrigins,
|
||||
methods: ["GET", "POST"]
|
||||
}
|
||||
});
|
||||
@@ -408,6 +421,7 @@ io.on('connection', (socket) => {
|
||||
// --- ADMIN COMMANDS ---
|
||||
|
||||
socket.on('admin_get_data', async () => {
|
||||
console.log('[ADMIN] Petición de datos del dashboard');
|
||||
const activeGamesData = Object.values(games).map(g => ({
|
||||
id: g.state.roomId,
|
||||
name: g.roomName,
|
||||
|
||||
Reference in New Issue
Block a user