-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
33 lines (27 loc) · 910 Bytes
/
node.js
File metadata and controls
33 lines (27 loc) · 910 Bytes
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
require('dotenv').config();
const express = require('express');
const fetch = require('node-fetch');
const app = express();
app.use(express.json());
app.post('/create-issue', async (req, res) => {
const token = process.env.YOUR_GITHUB_TOKEN; // Securely access the token
const data = req.body;
try {
const response = await fetch("https://api.github.com/repos/your-repo/issues", {
method: "POST",
headers: {
"Authorization": `token ${token}`,
"Accept": "application/vnd.github.v3+json"
},
body: JSON.stringify(data)
});
if (!response.ok) {
return res.status(response.status).send({ error: response.statusText });
}
const result = await response.json();
res.send(result);
} catch (error) {
res.status(500).send({ error: "Failed to create issue" });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));