This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (93 loc) · 2.72 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const fs = require("fs");
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const rateLimit = require("express-rate-limit");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const signupLimit = rateLimit({
windowMs: 60 * 1000 * 60 * 24 * 7,
max: 1,
});
const nodemailer = require("nodemailer");
/* dont enable
const transport = nodemailer.createTransport({
secureConnection: false,
host: "smtp-mail.outlook.com",
port: 587,
tls: {
ciphers:'SSLv3'
},
auth: {
user: "ReplitCoders@outlook.com", // use gmail - anonymous
pass: process.env.emailPass
}
});*/
app.set("view engine", "html");
app.engine("html", require("ejs").renderFile);
// fs.rmdirSync(".vscode", { recursive: true });
app.use(express.static("static"));
console.log("Look like we have one more viewer! (lol eh y did you come here)");
app.get("/", (_, res) => {
res.render("index");
console.log("Serving Home Page");
});
app.get("/haha-e", (_, res) => {
console.log("haha é\n".repeat(50));
res.render("haha-e");
});
app.get("/signup", (_, res) => {
res.render("signup");
console.log("Serving SIGNUP");
});
const ips = {};
app.post("/signup", signupLimit, (req, res) => {
//res.send("due to spam signup is currently disabled.")
//return
const current = Date.now();
const ip = req.ip;
if (!ips[ip]) {
ips[ip] = current;
setTimeout(() => {
delete ips[ip];
}, 2000);
} else if (current - ips[ip] < 2000) {
//console.log(ip);
delete ips[ip];
return res
.status(429)
.send(
"We received multiple requests from you in under a second. Please wait a while before submitting new requests."
); // read chat.
}
console.log("sending signup application email");
// https://www.w3schools.com/nodejs/nodejs_email.asp
/* DO NOT ENABLE NO MATTER WHAT
let mailOptions = {
from: 'ReplitCoders@outlook.com',
to: 'ReplitCoders@outlook.com',
subject: `New Application From ${req.body.Username}`,
text: `NEW APPLICATION! \nReplit Name: ${req.body.Username}, \nGithub: ${req.body.GitHub}.`
};
transport.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent successfully');
}
}); */
res.redirect("/signup_confirmed");
});
app.get("/signup_confirmed", (_, res) => {
console.log("Confirmed signup");
res.render("signup_confirmed");
});
app.get("/:user", (req, res) => {
if (fs.existsSync(`views/${req.params.user}.html`)) {
console.log("Serving user: " + req.params.user);
res.render(`${req.params.user}.html`);
} else res.status(404).render("404.html");
});
app.listen(8000, () => {
console.log("Server running.");
});