-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (29 loc) · 828 Bytes
/
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
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const { Octokit } = require('@octokit/rest');
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(bodyParser.json());
const octokit = new Octokit({
auth: process.env.GITHUB_API_TOKEN,
});
// GitHub API 路由
app.post('/api/github', async (req, res) => {
const { keyword } = req.body;
try {
const result = await octokit.search.repos({
q: `${keyword} stars:>100`,
sort: 'stars',
order: 'desc',
per_page: 5,
});
res.json(result.data.items);
} catch (error) {
res.status(500).json({ error: 'Error fetching GitHub repositories' });
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});