-
Notifications
You must be signed in to change notification settings - Fork 308
/
index.js
47 lines (41 loc) · 1.37 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
const jsonServer = require("json-server");
const express = require("express");
const path = require("path");
const server = jsonServer.create();
const router = jsonServer.router("./data/db.json");
const middlewares = jsonServer.defaults();
server.use(middlewares);
server.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
res.header("Referrer-Policy", "same-origin");
next();
})
server.get("/orderStatuses", (req, res, next) => {
setTimeout(() => {
next();
}, 1500);
});
server.use("/src", express.static(__dirname + "/src/"));
server.use("/home", (req, res) => {
res.sendFile(path.join(__dirname + "/index.html"));
});
server.use("/understanding", (req, res) => {
res.sendFile(path.join(__dirname + "/understanding.html"));
});
server.use("/consuming", (req, res) => {
res.sendFile(path.join(__dirname + "/consuming.html"));
});
server.use("/creating", (req, res) => {
res.sendFile(path.join(__dirname + "/creating.html"));
});
server.use("/iterating", (req, res) => {
res.sendFile(path.join(__dirname + "/iterating.html"));
});
server.use("/service-worker.js", (req, res) =>
res.sendFile(path.join(__dirname + "/service-worker.js"))
);
server.use(router);
const port = process.env.PORT || 3000
server.listen(port, () => {
console.log(`JSON Server is running on port ${port}`);
});