Spaces:
Running
Running
Update server.mjs
Browse files- server.mjs +18 -8
server.mjs
CHANGED
|
@@ -1,30 +1,40 @@
|
|
| 1 |
import express from 'express';
|
| 2 |
import path from 'path';
|
| 3 |
import { fileURLToPath } from 'url';
|
| 4 |
-
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 |
-
|
| 12 |
const distPath = path.join(__dirname, 'dist');
|
| 13 |
|
| 14 |
-
//
|
|
|
|
| 15 |
if (fs.existsSync(distPath)) {
|
| 16 |
-
console.log(`✅ Carpeta 'dist' encontrada
|
| 17 |
-
|
|
|
|
| 18 |
} else {
|
| 19 |
-
console.error(`❌ ERROR CRÍTICO: No se encuentra la carpeta 'dist'.
|
| 20 |
}
|
| 21 |
|
|
|
|
| 22 |
app.use(express.static(distPath));
|
| 23 |
|
|
|
|
| 24 |
app.get('*', (req, res) => {
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
});
|
| 27 |
|
| 28 |
app.listen(PORT, '0.0.0.0', () => {
|
| 29 |
-
console.log(`Servidor escuchando en http://0.0.0.0:${PORT}`);
|
| 30 |
});
|
|
|
|
| 1 |
import express from 'express';
|
| 2 |
import path from 'path';
|
| 3 |
import { fileURLToPath } from 'url';
|
| 4 |
+
import fs from 'fs';
|
| 5 |
|
| 6 |
const __filename = fileURLToPath(import.meta.url);
|
| 7 |
const __dirname = path.dirname(__filename);
|
| 8 |
+
|
| 9 |
+
// Puerto estándar de Hugging Face
|
| 10 |
const PORT = process.env.PORT || 7860;
|
| 11 |
|
| 12 |
const app = express();
|
|
|
|
| 13 |
const distPath = path.join(__dirname, 'dist');
|
| 14 |
|
| 15 |
+
// Diagnóstico de arranque
|
| 16 |
+
console.log("--- Iniciando Servidor CoinTube ---");
|
| 17 |
if (fs.existsSync(distPath)) {
|
| 18 |
+
console.log(`✅ Carpeta 'dist' encontrada.`);
|
| 19 |
+
const files = fs.readdirSync(distPath);
|
| 20 |
+
console.log(`📄 Archivos en raíz: ${files.join(', ')}`);
|
| 21 |
} else {
|
| 22 |
+
console.error(`❌ ERROR CRÍTICO: No se encuentra la carpeta 'dist'. Vite no construyó la app correctamente.`);
|
| 23 |
}
|
| 24 |
|
| 25 |
+
// Servir archivos estáticos
|
| 26 |
app.use(express.static(distPath));
|
| 27 |
|
| 28 |
+
// Manejar SPA (Single Page Application)
|
| 29 |
app.get('*', (req, res) => {
|
| 30 |
+
const indexPath = path.join(distPath, 'index.html');
|
| 31 |
+
if (fs.existsSync(indexPath)) {
|
| 32 |
+
res.sendFile(indexPath);
|
| 33 |
+
} else {
|
| 34 |
+
res.status(500).send('Error: index.html no encontrado. Revisa los logs de construcción.');
|
| 35 |
+
}
|
| 36 |
});
|
| 37 |
|
| 38 |
app.listen(PORT, '0.0.0.0', () => {
|
| 39 |
+
console.log(`🚀 Servidor escuchando en http://0.0.0.0:${PORT}`);
|
| 40 |
});
|