-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (36 loc) · 1.06 KB
/
server.js
File metadata and controls
43 lines (36 loc) · 1.06 KB
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
require("dotenv").config();
const express = require("express");
const { getCourses, getAssignments, getGrades, getUpcoming } = require("./canvas-client");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static("public"));
app.use(express.json());
app.get("/api/courses", async (req, res) => {
try {
res.json(await getCourses());
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.get("/api/courses/:id/assignments", async (req, res) => {
try {
res.json(await getAssignments(req.params.id));
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.get("/api/courses/:id/grades", async (req, res) => {
try {
res.json(await getGrades(req.params.id));
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.get("/api/upcoming", async (req, res) => {
try {
res.json(await getUpcoming());
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(PORT, () => console.log(`Server running at http://localhost:${PORT}`));