diff --git a/basic-info-node-backend/src/content/about.html b/basic-info-node-backend/src/content/about.html new file mode 100644 index 0000000..9345cf0 --- /dev/null +++ b/basic-info-node-backend/src/content/about.html @@ -0,0 +1,13 @@ + + + + + + About + + + +

Hello There

+

This is about as much about me as it is about you

+ + diff --git a/basic-info-node-backend/src/content/contact.html b/basic-info-node-backend/src/content/contact.html new file mode 100644 index 0000000..609a1b9 --- /dev/null +++ b/basic-info-node-backend/src/content/contact.html @@ -0,0 +1,14 @@ + + + + + + Contact + + + +

+ You really shouldn't reach out to me, but if you do I'll be glad you did +

+ + diff --git a/basic-info-node-backend/src/content/index.html b/basic-info-node-backend/src/content/index.html new file mode 100644 index 0000000..0cb0a9d --- /dev/null +++ b/basic-info-node-backend/src/content/index.html @@ -0,0 +1,12 @@ + + + + + + + + + +

Welcome Home

+ + diff --git a/basic-info-node-backend/src/server.js b/basic-info-node-backend/src/server.js new file mode 100644 index 0000000..61c7f81 --- /dev/null +++ b/basic-info-node-backend/src/server.js @@ -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(`

404 ${filename} NOT FOUND

${req.url}

`); + } + + res.writeHead(200, { "Content-Type": "text/html" }); + res.write(data); + return res.end(); + }); +}); + +server.listen(port, hostname, () => { + console.log(`Server running: http://${hostname}:${port}`); +});