forked from rickhanlonii/async-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (36 loc) · 1.01 KB
/
server.js
File metadata and controls
42 lines (36 loc) · 1.01 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
import express from "express";
const app = express();
const port = 8080;
import * as fakeData from "@/data/fake-data.js";
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept",
);
next();
});
app.get("/lessons", async (req, res) => {
const tab = req.query.tab;
const search = req.query.q;
await fakeData
.getLessons(tab, search, req.query.delay || 0)
.then((lessons) => {
res.send(JSON.stringify(lessons));
});
});
app.post("/lesson/:id/toggle", async (req, res) => {
await fakeData
.postLessonToggle(req.params.id, req.query.delay || 0)
.then(() => {
res.send(JSON.stringify({ status: "ok" }));
});
});
app.post("/login", async (req, res) => {
await fakeData.postLogin(req.query.delay || 0).then(() => {
res.send(JSON.stringify({ status: "ok" }));
});
});
app.listen(port, () => {
console.log("Server running on port " + port);
});