Spaces:
Running
Running
Upload 3 files
Browse files- backend/.env +2 -0
- backend/package.json +0 -1
- backend/server.js +68 -70
backend/.env
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Fallback database configuration for environments without PostgreSQL
|
| 2 |
+
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
|
backend/package.json
CHANGED
|
@@ -10,7 +10,6 @@
|
|
| 10 |
"dependencies": {
|
| 11 |
"express": "^4.18.2",
|
| 12 |
"cors": "^2.8.5",
|
| 13 |
-
"pg": "^8.11.0",
|
| 14 |
"dotenv": "^16.3.1"
|
| 15 |
},
|
| 16 |
"devDependencies": {
|
|
|
|
| 10 |
"dependencies": {
|
| 11 |
"express": "^4.18.2",
|
| 12 |
"cors": "^2.8.5",
|
|
|
|
| 13 |
"dotenv": "^16.3.1"
|
| 14 |
},
|
| 15 |
"devDependencies": {
|
backend/server.js
CHANGED
|
@@ -17,11 +17,63 @@ app.use(cors({
|
|
| 17 |
}));
|
| 18 |
app.use(express.json());
|
| 19 |
|
| 20 |
-
//
|
| 21 |
-
const
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
// Routes
|
| 27 |
app.get('/api/health', (req, res) => {
|
|
@@ -29,74 +81,20 @@ app.get('/api/health', (req, res) => {
|
|
| 29 |
});
|
| 30 |
|
| 31 |
// Mission Hubs routes
|
| 32 |
-
app.get('/api/missions',
|
| 33 |
-
|
| 34 |
-
const result = await pool.query('SELECT * FROM missions ORDER BY id');
|
| 35 |
-
res.json(result.rows);
|
| 36 |
-
} catch (err) {
|
| 37 |
-
console.error(err);
|
| 38 |
-
res.status(500).json({ error: 'Internal server error' });
|
| 39 |
-
}
|
| 40 |
});
|
| 41 |
|
| 42 |
-
app.get('/api/missions/:id',
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
return res.status(404).json({ error: 'Mission not found' });
|
| 48 |
-
}
|
| 49 |
-
res.json(result.rows[0]);
|
| 50 |
-
} catch (err) {
|
| 51 |
-
console.error(err);
|
| 52 |
-
res.status(500).json({ error: 'Internal server error' });
|
| 53 |
}
|
|
|
|
| 54 |
});
|
| 55 |
|
| 56 |
-
//
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
await pool.query(`
|
| 60 |
-
CREATE TABLE IF NOT EXISTS missions (
|
| 61 |
-
id SERIAL PRIMARY KEY,
|
| 62 |
-
name VARCHAR(255) NOT NULL,
|
| 63 |
-
description TEXT,
|
| 64 |
-
objectives TEXT,
|
| 65 |
-
target_actors TEXT,
|
| 66 |
-
created_at TIMESTAMP DEFAULT NOW(),
|
| 67 |
-
updated_at TIMESTAMP DEFAULT NOW()
|
| 68 |
-
)
|
| 69 |
-
`);
|
| 70 |
-
|
| 71 |
-
// Insert sample data if table is empty
|
| 72 |
-
const count = await pool.query('SELECT COUNT(*) FROM missions');
|
| 73 |
-
if (parseInt(count.rows[0].count) === 0) {
|
| 74 |
-
await pool.query(`
|
| 75 |
-
INSERT INTO missions (name, description, objectives, target_actors) VALUES
|
| 76 |
-
('Regenerative Economy', 'Climate, energy, biodiversity, jobs', 'Reduce carbon emissions, promote renewable energy, protect biodiversity, create green jobs', 'Government agencies, environmental organizations, businesses'),
|
| 77 |
-
('Well-being for All', 'Health, education, social protection', 'Improve healthcare access, enhance education quality, strengthen social protection systems', 'Healthcare providers, educational institutions, social services'),
|
| 78 |
-
('Just Digital Transition', 'Infrastructure, AI ethics and governance, data justice', 'Build equitable digital infrastructure, establish AI ethics guidelines, ensure data justice', 'Tech companies, policymakers, civil society'),
|
| 79 |
-
('Equity and Inclusion', 'Gender, migration, race, intergenerational justice', 'Promote gender equality, protect migrant rights, combat racial discrimination, ensure intergenerational justice', 'Human rights organizations, advocacy groups, government bodies'),
|
| 80 |
-
('Peace and Global Governance', 'Conflict, institutions, human rights', 'Prevent conflicts, strengthen international institutions, protect human rights', 'International organizations, peacekeeping bodies, legal institutions'),
|
| 81 |
-
('Resilient Local Economies', 'Urban-rural linkages, food systems, circular economy', 'Strengthen urban-rural connections, develop sustainable food systems, promote circular economy practices', 'Local governments, agricultural cooperatives, circular economy practitioners')
|
| 82 |
-
`);
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
console.log('Database initialized successfully');
|
| 86 |
-
} catch (err) {
|
| 87 |
-
console.error('Error initializing database:', err);
|
| 88 |
-
// Don't fail the app if database initialization fails - we can work without it for now
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
// Initialize database and start server
|
| 93 |
-
initializeDatabase().then(() => {
|
| 94 |
-
app.listen(PORT, '0.0.0.0', () => {
|
| 95 |
-
console.log('Server running on port ' + PORT);
|
| 96 |
-
});
|
| 97 |
-
}).catch((error) => {
|
| 98 |
-
console.error('Failed to initialize database, starting server without it:', error);
|
| 99 |
-
app.listen(PORT, '0.0.0.0', () => {
|
| 100 |
-
console.log('Server running on port ' + PORT + ' without database');
|
| 101 |
-
});
|
| 102 |
});
|
|
|
|
| 17 |
}));
|
| 18 |
app.use(express.json());
|
| 19 |
|
| 20 |
+
// In-memory data for prototype (no database required)
|
| 21 |
+
const missions = [
|
| 22 |
+
{
|
| 23 |
+
id: 1,
|
| 24 |
+
name: 'Regenerative Economy',
|
| 25 |
+
description: 'Climate, energy, biodiversity, jobs',
|
| 26 |
+
objectives: 'Reduce carbon emissions, promote renewable energy, protect biodiversity, create green jobs',
|
| 27 |
+
target_actors: 'Government agencies, environmental organizations, businesses',
|
| 28 |
+
created_at: new Date().toISOString(),
|
| 29 |
+
updated_at: new Date().toISOString()
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
id: 2,
|
| 33 |
+
name: 'Well-being for All',
|
| 34 |
+
description: 'Health, education, social protection',
|
| 35 |
+
objectives: 'Improve healthcare access, enhance education quality, strengthen social protection systems',
|
| 36 |
+
target_actors: 'Healthcare providers, educational institutions, social services',
|
| 37 |
+
created_at: new Date().toISOString(),
|
| 38 |
+
updated_at: new Date().toISOString()
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
id: 3,
|
| 42 |
+
name: 'Just Digital Transition',
|
| 43 |
+
description: 'Infrastructure, AI ethics and governance, data justice',
|
| 44 |
+
objectives: 'Build equitable digital infrastructure, establish AI ethics guidelines, ensure data justice',
|
| 45 |
+
target_actors: 'Tech companies, policymakers, civil society',
|
| 46 |
+
created_at: new Date().toISOString(),
|
| 47 |
+
updated_at: new Date().toISOString()
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
id: 4,
|
| 51 |
+
name: 'Equity and Inclusion',
|
| 52 |
+
description: 'Gender, migration, race, intergenerational justice',
|
| 53 |
+
objectives: 'Promote gender equality, protect migrant rights, combat racial discrimination, ensure intergenerational justice',
|
| 54 |
+
target_actors: 'Human rights organizations, advocacy groups, government bodies',
|
| 55 |
+
created_at: new Date().toISOString(),
|
| 56 |
+
updated_at: new Date().toISOString()
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
id: 5,
|
| 60 |
+
name: 'Peace and Global Governance',
|
| 61 |
+
description: 'Conflict, institutions, human rights',
|
| 62 |
+
objectives: 'Prevent conflicts, strengthen international institutions, protect human rights',
|
| 63 |
+
target_actors: 'International organizations, peacekeeping bodies, legal institutions',
|
| 64 |
+
created_at: new Date().toISOString(),
|
| 65 |
+
updated_at: new Date().toISOString()
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
id: 6,
|
| 69 |
+
name: 'Resilient Local Economies',
|
| 70 |
+
description: 'Urban-rural linkages, food systems, circular economy',
|
| 71 |
+
objectives: 'Strengthen urban-rural connections, develop sustainable food systems, promote circular economy practices',
|
| 72 |
+
target_actors: 'Local governments, agricultural cooperatives, circular economy practitioners',
|
| 73 |
+
created_at: new Date().toISOString(),
|
| 74 |
+
updated_at: new Date().toISOString()
|
| 75 |
+
}
|
| 76 |
+
];
|
| 77 |
|
| 78 |
// Routes
|
| 79 |
app.get('/api/health', (req, res) => {
|
|
|
|
| 81 |
});
|
| 82 |
|
| 83 |
// Mission Hubs routes
|
| 84 |
+
app.get('/api/missions', (req, res) => {
|
| 85 |
+
res.json(missions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
});
|
| 87 |
|
| 88 |
+
app.get('/api/missions/:id', (req, res) => {
|
| 89 |
+
const { id } = req.params;
|
| 90 |
+
const mission = missions.find(m => m.id === parseInt(id));
|
| 91 |
+
if (!mission) {
|
| 92 |
+
return res.status(404).json({ error: 'Mission not found' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
+
res.json(mission);
|
| 95 |
});
|
| 96 |
|
| 97 |
+
// Start server without database initialization
|
| 98 |
+
app.listen(PORT, '0.0.0.0', () => {
|
| 99 |
+
console.log('Server running on port ' + PORT + ' (no database required)');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
});
|