-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (33 loc) · 894 Bytes
/
server.js
File metadata and controls
35 lines (33 loc) · 894 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
30
31
32
33
34
35
import * as http from "http";
import * as fs from "fs";
const server = http.createServer((req, res) => {
if (req.url === "/") {
fs.readFile("./index.html", (err, data) => {
if (err) {
console.error(err);
res.writeHead(404);
res.end("Error loading index.html");
} else {
res.writeHead(200, { "Content-type": "text/html" });
res.end(data);
}
});
} else if (req.url === "/main.js") {
fs.readFile("./main.js", (err, data) => {
if (err) {
console.log(err);
res.writeHead(404);
res.end("Error loading main.js");
} else {
res.writeHead(200, { "Content-type": "application/json" });
res.end(data);
}
});
} else {
res.writeHead(404);
res.end("Not found");
}
});
server.listen(8000, () => {
console.log("Server running at http://localhost:8000/");
});