Spaces:
Running
Running
Create server.mjs
Browse files- server.mjs +36 -0
server.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import path from 'path';
|
| 3 |
+
import { fileURLToPath } from 'url';
|
| 4 |
+
|
| 5 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 6 |
+
const __dirname = path.dirname(__filename);
|
| 7 |
+
|
| 8 |
+
const PORT = process.env.PORT || 7860;
|
| 9 |
+
const app = express();
|
| 10 |
+
|
| 11 |
+
// --- ENDPOINT SEGURO DE CONFIGURACIÓN ---
|
| 12 |
+
// React llamará a esta ruta para obtener las credenciales
|
| 13 |
+
app.get('/api/config', (req, res) => {
|
| 14 |
+
try {
|
| 15 |
+
// Leemos el SECRETO de Hugging Face
|
| 16 |
+
const config = process.env.FIREBASE_CONFIG;
|
| 17 |
+
if (!config) {
|
| 18 |
+
return res.status(500).json({ error: "No hay configuración en el servidor" });
|
| 19 |
+
}
|
| 20 |
+
// Lo enviamos al frontend como JSON
|
| 21 |
+
res.json(JSON.parse(config));
|
| 22 |
+
} catch (error) {
|
| 23 |
+
res.status(500).json({ error: "Error parseando la configuración" });
|
| 24 |
+
}
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
// Servir archivos estáticos
|
| 28 |
+
app.use(express.static(path.join(__dirname, 'dist')));
|
| 29 |
+
|
| 30 |
+
app.get('*', (req, res) => {
|
| 31 |
+
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
app.listen(PORT, '0.0.0.0', () => {
|
| 35 |
+
console.log(`Servidor escuchando en http://0.0.0.0:${PORT}`);
|
| 36 |
+
});
|