const express = require('express'); const cors = require('cors'); const dotenv = require('dotenv'); const path = require('path'); dotenv.config(); const app = express(); // Use PORT from environment variable (for Hugging Face Spaces) or default to 3000 const PORT = process.env.PORT || 3000; // Middleware app.use(cors({ // Updated CORS for Hugging Face Spaces deployment origin: ['http://localhost:8501', 'http://localhost:5173', 'http://frontend:5173', 'http://0.0.0.0:5173', 'https://n4sm-platform.hf.space', 'https://*.hf.space'], credentials: true })); app.use(express.json()); // In-memory data for prototype (no database required) const missions = [ { id: 1, name: 'Regenerative Economy', description: 'Climate, energy, biodiversity, jobs', objectives: 'Reduce carbon emissions, promote renewable energy, protect biodiversity, create green jobs', target_actors: 'Government agencies, environmental organizations, businesses', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 2, name: 'Well-being for All', description: 'Health, education, social protection', objectives: 'Improve healthcare access, enhance education quality, strengthen social protection systems', target_actors: 'Healthcare providers, educational institutions, social services', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 3, name: 'Just Digital Transition', description: 'Infrastructure, AI ethics and governance, data justice', objectives: 'Build equitable digital infrastructure, establish AI ethics guidelines, ensure data justice', target_actors: 'Tech companies, policymakers, civil society', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 4, name: 'Equity and Inclusion', description: 'Gender, migration, race, intergenerational justice', objectives: 'Promote gender equality, protect migrant rights, combat racial discrimination, ensure intergenerational justice', target_actors: 'Human rights organizations, advocacy groups, government bodies', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 5, name: 'Peace and Global Governance', description: 'Conflict, institutions, human rights', objectives: 'Prevent conflicts, strengthen international institutions, protect human rights', target_actors: 'International organizations, peacekeeping bodies, legal institutions', created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 6, name: 'Resilient Local Economies', description: 'Urban-rural linkages, food systems, circular economy', objectives: 'Strengthen urban-rural connections, develop sustainable food systems, promote circular economy practices', target_actors: 'Local governments, agricultural cooperatives, circular economy practitioners', created_at: new Date().toISOString(), updated_at: new Date().toISOString() } ]; // Routes app.get('/api/health', (req, res) => { res.json({ status: 'OK', message: 'NextGen SDG Platform API is running' }); }); // Mission Hubs routes app.get('/api/missions', (req, res) => { res.json(missions); }); app.get('/api/missions/:id', (req, res) => { const { id } = req.params; const mission = missions.find(m => m.id === parseInt(id)); if (!mission) { return res.status(404).json({ error: 'Mission not found' }); } res.json(mission); }); // Start server without database initialization app.listen(PORT, '0.0.0.0', () => { console.log('Server running on port ' + PORT + ' (no database required)'); });