salomonsky commited on
Commit
6358cbc
·
verified ·
1 Parent(s): 6eb0bba

Update server.mjs

Browse files
Files changed (1) hide show
  1. server.mjs +17 -4
server.mjs CHANGED
@@ -2,22 +2,35 @@ import express from 'express';
2
  import path from 'path';
3
  import { fileURLToPath } from 'url';
4
 
5
- // --- Configuración ---
6
  const __filename = fileURLToPath(import.meta.url);
7
  const __dirname = path.dirname(__filename);
8
 
9
- // CAMBIO 1: Usar puerto 7860 por defecto (Estándar de Hugging Face)
10
  const PORT = process.env.PORT || 7860;
11
-
12
  const app = express();
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  app.use(express.static(path.join(__dirname, 'dist')));
15
 
16
  app.get('*', (req, res) => {
17
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
18
  });
19
 
20
- // CAMBIO 2: Escuchar explícitamente en '0.0.0.0'
21
  app.listen(PORT, '0.0.0.0', () => {
22
  console.log(`Servidor escuchando en http://0.0.0.0:${PORT}`);
23
  });
 
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
  });