-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (27 loc) · 900 Bytes
/
app.js
File metadata and controls
29 lines (27 loc) · 900 Bytes
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
const http = require("http");
const fs = require("fs");
const path = require("path");
const taskRoutes = require("./routes/taskRoutes");
const PORT = 9000;
const server = http.createServer((req, res) => {
if (req.url === "/" && req.method === "GET") {
// Serve the index.html file
fs.readFile(path.join(__dirname, "views", "index.html"), (err, content) => {
if (err) {
res.writeHead(500, { "Content-Type": "text/plain" });
res.end("Error loading page");
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(content);
}
});
} else if (req.url.startWith("/tasks")) {
taskRoutes(req, res);
} else {
res.writeHead(404, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Route not found" }));
}
});
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});