-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (48 loc) · 1.22 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require("express");
const app = express();
const fs = require('fs');
const port = 80;
const listener = app.listen(port, function() {
console.log("Your app is listening on port " + listener.address().port);
});
app.get("/send", async function(req, res) {
if (req.query.message) {
if (decodeURIComponent(req.query.message).value >= 2000) {
res.send("message above 2000 characters")
} else {
if (fs.readFileSync('chat.txt').toString() == "") {
sendvar = ""
} else {
chatlog = fs.readFileSync('chat.txt').toString()
sendvar = "<br>" + chatlog
}
fs.writeFile("chat.txt", req.query.message + sendvar, function(err) {
if (err) throw err;
});
res.send("message sent")
}
} else {
res.send("message undefined")
}
return
});
app.get("/chat", async function(req, res) {
res.sendFile(__dirname + "/chat.txt")
return
});
app.get("/", async function(req, res) {
res.sendFile(__dirname + "/index.html")
return
});
app.get("*", async function(req, res) {
res.send("404")
return
});
function resetChat() {
fs.writeFile("chat.txt", "", function(err) {
if (err) throw err;
});
setTimeout(() => {
resetChat()
}, 3600000)
}