-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
65 lines (59 loc) · 1.85 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const express = require('express');
const path = require('path');
const cors = require("cors");
const bodyParser = require('body-parser');
const config = require('./config');
const axios = require('axios');
const { json } = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.use('/assets', express.static(path.join(__dirname, 'public/assets')));
app.get("/", (req, res) => {
// let repoInfo;
// axios({
// method: "get",
// url: `https://api.github.com/users/${config.githubUsername}/repos`,
// headers: {
// Authorization: `Bearer ${config.githubToken}`,
// "Content-Type": "application/json",
// "Accept": "application/vnd.github.mercy-preview+json" // MUST ADD TO INCLUDE TOPICS
// }
// }).then(response => {
// repoInfo = response.data;
// res.render('index', {
// repoInfo: repoInfo
// });
// })
// .catch(err => {
// console.log(err);
// });
res.render('index')
})
app.get("/projects", (req, res) => {
let repoInfo;
axios({
method: "get",
url: `https://api.github.com/users/${config.githubUsername}/repos`,
headers: {
Authorization: `Bearer ${config.githubToken}`,
"Content-Type": "application/json",
"Accept": "application/vnd.github.mercy-preview+json" // MUST ADD TO INCLUDE TOPICS
}
}).then(response => {
repoInfo = response.data;
res.render('projects', {
repoInfo: repoInfo
});
})
.catch(err => {
console.log(err);
});
});
app.listen(port, () => {
console.log(`listening on port: ${port}`);
})