Spaces:
Build error
Build error
Download index.js from OGLingLing/MovieWindScraper: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/spaces/OGLingLing/MovieWindScraper/resolve/main/index.js
- Command line
-
hf download hf://spaces/OGLingLing/MovieWindScraper/index.js
-
curl -L -o index.js https://huggingface.co/spaces/OGLingLing/MovieWindScraper/resolve/main/index.js
2.84 kB
| require('dotenv').config(); | |
| const express = require('express'); | |
| const cors = require('cors'); | |
| const app = express(); | |
| // --- IMPORTACIÓN DE RUTAS --- | |
| const movieRoutes = require('./routes/movie_routes'); | |
| const authRoutes = require('./routes/auth_routes'); | |
| const adminRoutes = require('./routes/admin_routes'); | |
| const authController = require('./controllers/auth_controller'); | |
| const watchlistRoutes = require('./routes/watchlist_routes'); | |
| const scraperRoutes = require('./routes/scraper_routes'); | |
| const streamRoutes = require('./routes/stream_routes'); | |
| // 1. CONFIGURACIÓN DE MIDDLEWARES | |
| // CORRECCIÓN: Añadimos la URL de Hugging Face y Render para que puedan hablar entre ellos | |
| const allowedOrigins = [ | |
| 'https://oglingling.github.io', | |
| 'http://localhost:3000', | |
| 'http://localhost:5173', | |
| /\.hf\.space$/, // Permite cualquier subdominio de Hugging Face | |
| /\.onrender\.com$/ // Permite cualquier subdominio de Render | |
| ]; | |
| app.use(cors({ | |
| origin: (origin, callback) => { | |
| // Permitir peticiones sin origen (como apps móviles o Postman) | |
| if (!origin) return callback(null, true); | |
| const isAllowed = allowedOrigins.some(allowed => { | |
| if (allowed instanceof RegExp) return allowed.test(origin); | |
| return allowed === origin; | |
| }); | |
| if (isAllowed) return callback(null, true); | |
| return callback(new Error('Origen no permitido por CORS')); | |
| }, | |
| methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], | |
| allowedHeaders: ['Content-Type', 'Accept', 'Authorization', 'x-api-key'] // Añadimos x-api-key por seguridad | |
| })); | |
| app.use(express.json()); | |
| app.use(express.static('public')); | |
| // 2. DEFINICIÓN DE PUNTOS DE ENTRADA | |
| app.use('/api/movies', movieRoutes); | |
| app.use('/api/auth', authRoutes); | |
| app.use('/api/admin', adminRoutes); | |
| app.use('/api/watchlist', watchlistRoutes); | |
| // Prefijos para scraper y stream | |
| app.use('/api', scraperRoutes); | |
| app.use('/api', streamRoutes); | |
| app.get('/api/users', authController.getUserByEmail); | |
| // 3. RUTA DE SALUD (Crítica para Hugging Face) | |
| app.get('/', (req, res) => { | |
| res.status(200).send('Servidor MOVIEWIND Activo 🚀'); | |
| }); | |
| app.get('/health', (req, res) => res.status(200).send('OK')); | |
| // Middleware 404 | |
| app.use((req, res) => { | |
| console.log('❌ 404 Capturado en la ruta:', req.originalUrl); | |
| res.status(404).json({ error: 'Not Found', path: req.originalUrl }); | |
| }); | |
| // 4. ARRANQUE DEL SERVIDOR | |
| // CORRECCIÓN: Hugging Face requiere el puerto 7860 para mostrarse como "Running" | |
| const PORT = process.env.PORT || 7860; | |
| const server = app.listen(PORT, '0.0.0.0', () => { | |
| console.log(`🚀 Scraper activo en puerto ${PORT}`); | |
| console.log(`🔗 Endpoint de extracción listo en: /api/extract`); | |
| }); | |
| // Aumentamos el timeout porque el scraping puede ser lento | |
| server.timeout = 120000; |