mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-25 22:10:43 -05:00
basic node webserver
This commit is contained in:
parent
b66089f97e
commit
e3737ba712
4 changed files with 69 additions and 0 deletions
13
basic-info-node-backend/src/content/about.html
Normal file
13
basic-info-node-backend/src/content/about.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>About</title>
|
||||||
|
<link href="css/style.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello There</h1>
|
||||||
|
<p>This is about as much about me as it is about you</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
basic-info-node-backend/src/content/contact.html
Normal file
14
basic-info-node-backend/src/content/contact.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Contact</title>
|
||||||
|
<link href="css/style.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
You really shouldn't reach out to me, but if you do I'll be glad you did
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
12
basic-info-node-backend/src/content/index.html
Normal file
12
basic-info-node-backend/src/content/index.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title></title>
|
||||||
|
<link href="css/style.css" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome Home</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
30
basic-info-node-backend/src/server.js
Normal file
30
basic-info-node-backend/src/server.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
const { createServer } = require("node:http");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const hostname = "127.0.0.1";
|
||||||
|
const port = 8080;
|
||||||
|
const pageURL = new URL("http://localhost:8080/");
|
||||||
|
|
||||||
|
const server = createServer((req, res) => {
|
||||||
|
let filename = "./src/content/index.html";
|
||||||
|
|
||||||
|
if (req.url === "/contact-me") {
|
||||||
|
filename = "./src/content/contact.html";
|
||||||
|
} else if (req.url !== "/") {
|
||||||
|
filename = "./src/content" + req.url + ".html";
|
||||||
|
}
|
||||||
|
fs.readFile(filename, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(404, { "Content-Type": "text/html" });
|
||||||
|
return res.end(`<h1>404 ${filename} NOT FOUND</h1><p>${req.url}</p>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(200, { "Content-Type": "text/html" });
|
||||||
|
res.write(data);
|
||||||
|
return res.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(port, hostname, () => {
|
||||||
|
console.log(`Server running: http://${hostname}:${port}`);
|
||||||
|
});
|
Loading…
Reference in a new issue