-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
31 lines (24 loc) · 808 Bytes
/
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
// index.js or app.js
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const path = require("path");
const getPinnedRepo = require("./utils/getPinnedRepo");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, "./public")));
// Home page
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/public/index.html'));
});
// Route to handle the username-specific API
app.get('/:username', async (req, res) => {
const username = req.params.username;
const pinnedRepos = await getPinnedRepo(username);
res.json({
data: pinnedRepos
});
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});