working version

This commit is contained in:
ak 2023-08-24 15:47:06 -07:00
parent 7ce79f9bcd
commit 44a80d0553
5 changed files with 117 additions and 0 deletions

20
404.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>404</title>
</head>
<body>
<br />
<center>
<header class="d-flex flex-row w-100">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact-me">Contact Me</a>
</header>
<br />
Whoops! Page not found!
</center>
</body>
</html>

20
about.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>About</title>
</head>
<body>
<br />
<center>
<header class="d-flex flex-row w-100">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact-me">Contact Me</a>
</header>
<br />
About me: I made this website
</center>
</body>
</html>

20
contact-me.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Contact Me</title>
</head>
<body>
<br />
<center>
<header class="d-flex flex-row w-100">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact-me">Contact Me</a>
</header>
<br />
This is where my contact information would be
</center>
</body>
</html>

20
index.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index</title>
</head>
<body>
<br />
<center>
<header class="d-flex flex-row w-100">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact-me">Contact Me</a>
</header>
<br />
Welcome to the home page!
</center>
</body>
</html>

37
index.js Normal file
View file

@ -0,0 +1,37 @@
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);