cointube / server.mjs
salomonsky's picture
Update server.mjs
6358cbc verified
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PORT = process.env.PORT || 7860;
const app = express();
// --- ENDPOINT SEGURO DE CONFIGURACIÓN ---
// React llamará a esta ruta para obtener las credenciales
app.get('/api/config', (req, res) => {
try {
// Leemos el SECRETO de Hugging Face
const config = process.env.FIREBASE_CONFIG;
if (!config) {
return res.status(500).json({ error: "No hay configuración en el servidor" });
}
// Lo enviamos al frontend como JSON
res.json(JSON.parse(config));
} catch (error) {
res.status(500).json({ error: "Error parseando la configuración" });
}
});
// Servir archivos estáticos
app.use(express.static(path.join(__dirname, 'dist')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`Servidor escuchando en http://0.0.0.0:${PORT}`);
});