Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
{

"dependencies": {
"chalk": "^5.0.0",
"prompt-sync": "^4.2.0"
Expand Down
66 changes: 49 additions & 17 deletions run.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
const prompt = require("prompt-sync")
const chalk = require("chalk")
const path = require('path');
const warn = function(message, color){
if (!color) color = red
console.log(chalk[color](message))
}

let prompt = require("prompt-sync")()
let chalk = import("chalk")
let path = require("path")
let fs = require("fs")
let log = console.log;
let http = require("http")

if (path.existsSync("/data")) { // or fs.existsSync
warn("WARNING: Folder \"data\" will be erased and rebuilt if you proceed")
if (fs.existsSync("data")) {
console.log("WARNING: Folder \"data\" will be erased and rebuilt if you proceed")
const answer = prompt("Would you like to proceed? (S/N)")
if (String(answer).toUpperCase=="S"){
//delete
console.log("Done")
} else if (String(answer).toUpperCase=="N"){
if (answer.toUpperCase() =="S"){
log("removing")
fs.rmdirSync("data",{recursive: true})
console.log("Done!")
console.log("Now we can start the HTTP server lol")

} else if (answer.toUpperCase() =="N"){
console.log("Goodbye!")
exit(0)
process.exit(0)
}else{
warn("Not a valid answer. Exiting...")
exit(1)
console.log("Not a valid answer. Exiting...")
process.exit(1)
}
}

const requestListener = function (req, res) {
log(req.url)
if (req.url === "/test"){
fs.readFile("templates/rick.html", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
}else if (req.url === "/"){

}else {
fs.readFile("static" + req.url, function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
}
}

const server = http.createServer(requestListener);
log("Server created. Starting...")
server.listen(80);
Binary file added static/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions templates/rick.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>Test</title>
</head>
<body>
<iframe height="350" width="600"
src="https://www.youtube.com/embed/dQw4w9WgXcQ">
</iframe>
</body>
</html>