forked from fac19/week4-JICG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
24 lines (22 loc) · 863 Bytes
/
router.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
const templates = require("./templates");
const handlers = require("./handlers");
const router = (req, res) => {
const url = req.url;
if (url === "/" && req.method === "GET") {
res.writeHead(200, { "content-type": "text/html" });
res.end(templates.home());
} else if (url.includes("public")) {
handlers.publicHandler(req, res);
} else if (url === "/" && req.method === "DELETE") {
handlers.deleteHandler(req, res);
} else if (url === "/write" && req.method === "GET") {
res.writeHead(200, { "content-type": "text/html" });
res.end(templates.write());
} else if (url === "/write" && req.method === "POST") {
handlers.postHandler(req, res);
} else {
res.writeHead(404, { "content-type": "text/html" });
res.end(templates.missing());
}
};
module.exports = router;