salomonsky commited on
Commit
3810731
·
verified ·
1 Parent(s): b5ade04

Update server.mjs

Browse files
Files changed (1) hide show
  1. server.mjs +10 -21
server.mjs CHANGED
@@ -5,39 +5,28 @@ import fs from 'fs';
5
 
6
  const __filename = fileURLToPath(import.meta.url);
7
  const __dirname = path.dirname(__filename);
 
8
  const PORT = process.env.PORT || 7860;
9
 
10
  const app = express();
 
11
  const distPath = path.join(__dirname, 'dist');
12
 
13
- console.log("--- Iniciando Servidor CoinTube ---");
14
  if (fs.existsSync(distPath)) {
15
- console.log(`✅ Carpeta 'dist' encontrada.`);
16
- const files = fs.readdirSync(distPath);
17
- console.log(`📄 Archivos en raíz: ${files.join(', ')}`);
18
  } else {
19
- console.error(`❌ ERROR CRÍTICO: No se encuentra la carpeta 'dist'. Vite no construyó la app.`);
 
 
20
  }
21
 
22
- // 🛑 PARCHE CRÍTICO: Sobreescribe el MIME Type para los archivos .jsx
23
- app.use((req, res, next) => {
24
- if (req.url.endsWith('.jsx')) {
25
- res.type('application/javascript');
26
- }
27
- next();
28
- });
29
-
30
- // Servir archivos estáticos (Ahora incluye la regla del .jsx)
31
  app.use(express.static(distPath));
32
 
33
- // Manejar SPA
34
  app.get('*', (req, res) => {
35
- const indexPath = path.join(distPath, 'index.html');
36
- if (fs.existsSync(indexPath)) {
37
- res.sendFile(indexPath);
38
- } else {
39
- res.status(500).send('Error: index.html no encontrado. Revisa los logs de construcción.');
40
- }
41
  });
42
 
43
  app.listen(PORT, '0.0.0.0', () => {
 
5
 
6
  const __filename = fileURLToPath(import.meta.url);
7
  const __dirname = path.dirname(__filename);
8
+ // Puerto 7860 obligatorio para Hugging Face
9
  const PORT = process.env.PORT || 7860;
10
 
11
  const app = express();
12
+ // Definimos explícitamente la ruta a la carpeta compilada
13
  const distPath = path.join(__dirname, 'dist');
14
 
15
+ // --- VERIFICACIÓN DE SEGURIDAD ---
16
  if (fs.existsSync(distPath)) {
17
+ console.log(`✅ Carpeta 'dist' encontrada. Sirviendo aplicación compilada.`);
 
 
18
  } else {
19
+ console.error(`❌ ERROR CRÍTICO: No existe la carpeta 'dist'.`);
20
+ console.error(` Esto significa que 'npm run build' falló o no se ejecutó.`);
21
+ console.error(` El servidor intentará servir archivos fuente, lo cual fallará en el navegador.`);
22
  }
23
 
24
+ // 1. Servir archivos estáticos SÓLO desde 'dist'
 
 
 
 
 
 
 
 
25
  app.use(express.static(distPath));
26
 
27
+ // 2. Cualquier otra ruta, devuelve el index.html COMPILADO (no el de la raíz)
28
  app.get('*', (req, res) => {
29
+ res.sendFile(path.join(distPath, 'index.html'));
 
 
 
 
 
30
  });
31
 
32
  app.listen(PORT, '0.0.0.0', () => {