37 lines
798 B
JavaScript
37 lines
798 B
JavaScript
const http = require("node:http");
|
|
const fs = require("node:fs");
|
|
|
|
const SERVER = http.createServer();
|
|
const PORT = 8080;
|
|
|
|
const HOME = fs.readFileSync("./index.html");
|
|
const ABOUT = fs.readFileSync("./about.html");
|
|
const CONTACT = fs.readFileSync("./contact-me.html");
|
|
const ERROR = fs.readFileSync("./404.html");
|
|
|
|
SERVER.on("request", (req, res) => {
|
|
switch (req.url) {
|
|
case "/":
|
|
res.writeHead(200);
|
|
res.end(HOME);
|
|
break;
|
|
case "/index":
|
|
res.writeHead(200);
|
|
res.end(HOME);
|
|
break;
|
|
case "/about":
|
|
res.writeHead(200);
|
|
res.end(ABOUT);
|
|
break;
|
|
case "/contact-me":
|
|
res.writeHead(200);
|
|
res.end(CONTACT);
|
|
break;
|
|
default:
|
|
res.writeHead(404);
|
|
res.end(ERROR);
|
|
break;
|
|
}
|
|
});
|
|
|
|
SERVER.listen(PORT);
|