2023-01-30 07:40:00 +01:00
|
|
|
const http = require("http");
|
|
|
|
const fs = require("fs");
|
2023-02-04 18:54:00 +01:00
|
|
|
const qs = require("querystring");
|
2023-01-30 07:40:00 +01:00
|
|
|
|
|
|
|
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) {
|
|
|
|
if (error) {
|
|
|
|
res.writeHead(404);
|
|
|
|
res.write("Error: File not found.");
|
|
|
|
} else {
|
|
|
|
res.write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.url === "/") {
|
|
|
|
res.statusCode = 200;
|
|
|
|
res.setHeader("Content-Type", "text/html");
|
|
|
|
fs.readFile("./pages/home.html", function(error, data) {
|
|
|
|
if (error) {
|
|
|
|
res.writeHead(404);
|
|
|
|
res.write("Error: File not found.");
|
|
|
|
} else {
|
|
|
|
res.write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
2023-02-04 18:54:00 +01:00
|
|
|
|
|
|
|
if (req.method === "POST" && req.url === "/members") {
|
|
|
|
res.statusCode = 200;
|
|
|
|
res.setHeader("Content-Type", "text/html");
|
|
|
|
var body = "";
|
|
|
|
|
|
|
|
req.on("data", function(data) {
|
|
|
|
body = body + data;
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on("end", function() {
|
|
|
|
var post = qs.parse(body);
|
|
|
|
if (post.username === "sweatshirt" && post.password === "Daemons0!") {
|
|
|
|
res.writeHead(301, { Location: "/sweatshirt" });
|
|
|
|
} else {
|
|
|
|
res.write("try again.");
|
|
|
|
}
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.url === "/sweatshirt") {
|
|
|
|
res.statusCode = 200;
|
|
|
|
res.setHeader("Content-Type", "text/html");
|
|
|
|
fs.readFile("./pages/sweatshirt.html", function(error, data) {
|
|
|
|
if (error) {
|
|
|
|
res.writeHead(404);
|
|
|
|
res.write("Error: File not found.");
|
|
|
|
} else {
|
|
|
|
res.write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-30 07:40:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const port = process.env.port || 8080;
|
|
|
|
|
|
|
|
server.listen(port, () => console.log(`Server running on port ${port}`));
|