-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.js
38 lines (32 loc) · 1.17 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import { GitHubBountyFetcher } from './github-bounties.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3000;
// Serve static files
app.use(express.static(__dirname));
// Add CORS headers
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
// Create bounties endpoint that fetches real data
app.get('/bounties.json', async (req, res) => {
try {
console.log('Fetching bounties...');
const fetcher = new GitHubBountyFetcher();
const bounties = await fetcher.fetchBountyIssues();
console.log('Bounties response:', bounties);
res.json(bounties);
} catch (error) {
console.error('Detailed error:', error);
res.status(500).json({ error: 'Failed to fetch bounties', details: error.message });
}
});
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});