figured out css loading and styling patch 1 for home page.

This commit is contained in:
sweatshirt0 2023-01-27 00:00:10 -05:00
parent ad0e00b99b
commit fd579de898
4 changed files with 39 additions and 19 deletions

View File

@ -1,16 +0,0 @@
<html>
<head>
<meta charset="UTF-8" />
<title>Libcasa-Chan</title>
</head>
<body>
<div class="whole-wrapper">
<div class="nav-wrapper">
<a class="home" href="/">Home</a>
</div>
<div class="title-wrapper">
<h1 class="title">Home</h1>
</div>
</div>
</body>
</html>

View File

@ -1,7 +1,9 @@
<!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Libcasa-Chan</title> <title>Libcasa-Chan</title>
<link rel="stylesheet" type="text/css" href="/styles/styles.css" />
</head> </head>
<body> <body>
<div class="whole-wrapper"> <div class="whole-wrapper">
@ -12,6 +14,8 @@
<div class="title-wrapper"> <div class="title-wrapper">
<h1 class="title">Home</h1> <h1 class="title">Home</h1>
</div> </div>
<div class="discussion-wrapper">
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -2,10 +2,19 @@ const http = require("http");
const fs = require("fs"); const fs = require("fs");
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
if (req.url === "/styles/styles.css" ) {
res.statusCode = 200;
res.setHeader("Content-Type", "text/css");
fs.readFile("styles/styles.css", function(error, data) {
res.write(data);
res.end();
});
}
if (req.url === "/") { if (req.url === "/") {
res.statusCode = 200; res.statusCode = 200;
res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Type", "text/html");
fs.readFile("index.html", function(error, data) { fs.readFile("./pages/index.html", function(error, data) {
if (error) { if (error) {
res.writeHead(404); res.writeHead(404);
res.write("Error: File not found."); res.write("Error: File not found.");
@ -13,9 +22,24 @@ const server = http.createServer((req, res) => {
res.write(data); res.write(data);
} }
res.end(); res.end();
}) });
} }
})
if (req.url === "/about") {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
fs.readFile("./pages/about.html", function(error, data) {
if (error) {
res.writeHead(404);
res.write("Error: File not found.");
} else {
res.write(data);
}
res.end();
});
}
});
const port = process.env.port || 8000; const port = process.env.port || 8000;

8
styles/styles.css Normal file
View File

@ -0,0 +1,8 @@
body {
background-color: black;
font-family: sans-serif;
}
.title {
color: white;
}