-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.js
30 lines (27 loc) · 1.01 KB
/
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
25
26
27
28
29
30
const homeHandler = require("./handlers/home");
const createPost = require("./handlers/createPost");
const missingHandler = require("./handlers/missing");
const publicHandler = require("./handlers/public.js");
const displayForm = require("./handlers/displayForm");
const imageHandler = require("./handlers/image.js");
const fs = require("fs");
function router(request, response) {
const endpoint = request.url;
console.log("router -> endpoint", endpoint)
const method = request.method;
// const filePath = path.join(__dirname, "/public");
if (endpoint === "/") {
homeHandler(request, response);
} else if (endpoint.includes("public")) {
publicHandler(request, response)
} else if (method === "POST" && endpoint === "/create-post") {
createPost(request, response);
} else if (endpoint === "/displayForm") {
displayForm(request, response);
} else if (endpoint.includes("images")) {
imageHandler(request, response)
} else {
missingHandler(request, response);
}
}
module.exports = router;