Skip to content

Commit 876b29e

Browse files
authored
Merge pull request #3 from J-P-S-O/master
Master
2 parents 6b4b161 + 97dc623 commit 876b29e

4 files changed

Lines changed: 61 additions & 18 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{
1+
{
2+
23
"dependencies": {
34
"chalk": "^5.0.0",
45
"prompt-sync": "^4.2.0"

run.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
1-
const prompt = require("prompt-sync")
2-
const chalk = require("chalk")
3-
const path = require('path');
4-
const warn = function(message, color){
5-
if (!color) color = red
6-
console.log(chalk[color](message))
7-
}
8-
1+
let prompt = require("prompt-sync")()
2+
let chalk = import("chalk")
3+
let path = require("path")
4+
let fs = require("fs")
5+
let log = console.log;
6+
let http = require("http")
97

10-
if (path.existsSync("/data")) { // or fs.existsSync
11-
warn("WARNING: Folder \"data\" will be erased and rebuilt if you proceed")
8+
if (fs.existsSync("data")) {
9+
console.log("WARNING: Folder \"data\" will be erased and rebuilt if you proceed")
1210
const answer = prompt("Would you like to proceed? (S/N)")
13-
if (String(answer).toUpperCase=="S"){
14-
//delete
15-
console.log("Done")
16-
} else if (String(answer).toUpperCase=="N"){
11+
if (answer.toUpperCase() =="S"){
12+
log("removing")
13+
fs.rmdirSync("data",{recursive: true})
14+
console.log("Done!")
15+
console.log("Now we can start the HTTP server lol")
16+
17+
} else if (answer.toUpperCase() =="N"){
1718
console.log("Goodbye!")
18-
exit(0)
19+
process.exit(0)
1920
}else{
20-
warn("Not a valid answer. Exiting...")
21-
exit(1)
21+
console.log("Not a valid answer. Exiting...")
22+
process.exit(1)
2223
}
2324
}
25+
26+
const requestListener = function (req, res) {
27+
log(req.url)
28+
if (req.url === "/test"){
29+
fs.readFile("templates/rick.html", function (err,data) {
30+
if (err) {
31+
res.writeHead(404);
32+
res.end(JSON.stringify(err));
33+
return;
34+
}
35+
res.writeHead(200);
36+
res.end(data);
37+
});
38+
}else if (req.url === "/"){
39+
40+
}else {
41+
fs.readFile("static" + req.url, function (err,data) {
42+
if (err) {
43+
res.writeHead(404);
44+
res.end(JSON.stringify(err));
45+
return;
46+
}
47+
res.writeHead(200);
48+
res.end(data);
49+
});
50+
}
51+
}
52+
53+
const server = http.createServer(requestListener);
54+
log("Server created. Starting...")
55+
server.listen(80);

static/favicon.ico

190 KB
Binary file not shown.

templates/rick.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>Test</title>
4+
</head>
5+
<body>
6+
<iframe height="350" width="600"
7+
src="https://www.youtube.com/embed/dQw4w9WgXcQ">
8+
</iframe>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)