This repository was archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (67 loc) · 2.7 KB
/
index.js
File metadata and controls
79 lines (67 loc) · 2.7 KB
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
const express = require("express");
const app = express();
const fs = require('fs');
app.use("/static", express.static(__dirname + "/static"));
app.use('/js', express.static(__dirname + '/js'));
app.use("favicon.ico", express.static(__dirname + "/favicon.ico"));
app.get("/login", async (_, res) => {
console.log(`Signing in [DEBUG]`);
res.sendFile(`${__dirname}/views/replAuth2.html`);
});
app.get("/", async (req, res) => {
let username = req.get("X-REPLIT-USER-NAME");
let loginURL = '#';
if(!username || username.length == 0) {
username = "Log In";
loginURL = "/login";
}
console.log(`Yeeet, [DEBUG] we running in home page`);
res.send(fs.readFileSync(`/${__dirname}/views/home.html`).toString().split("{{USERNAME}}").join(username).split("{{LOGIN_URL}}").join(loginURL));
});
app.get("/posts", (req, res) => {
let username = req.get("X-REPLIT-USER-NAME");
let loginURL = '#';
if(!username || username.length == 0) {
username = "Log In";
loginURL = "/login";
}
console.log("We in the posts page [DEBUG]");
res.send(fs.readFileSync(`/${__dirname}/views/posts.html`).toString().split("{{USERNAME}}").join(username).split("{{LOGIN_URL}}").join(loginURL));
});
app.get("/suggestions", (req, res) => {
let username = req.get("X-REPLIT-USER-NAME");
let loginURL = '#';
let message = '';
if(!username || username.length == 0) {
username = "Log In";
loginURL = "/login";
message = "<h3>You must log in before submitting this form</h3>";
}
console.log(
"Hello, is this the debug center, yes, we are running the suggestions"
);
res.send(fs.readFileSync(`/${__dirname}/views/suggestions.html`).toString().split("{{USERNAME}}").join(username).split("{{LOGIN_URL}}").join(loginURL).split("{{MESSAGE}}").join(message));
});
app.post("/api/suggestions", require("body-parser")(), (req, res) => {
console.log(
"Hello, is this the debug center, yes, we are running the suggestions API"
);
let body = req.body;
console.log("Username:", req.get("X-REPLIT-USER-NAME")); // Should we authenticate with Repl Auth? -- Yes we should ~ Whippingdot
console.log("Suggestion:", body.suggestion);
// We need to add a DB. ReplDB maybe? -- I don't know, we need a db or a file ~ Whippingdot
res.redirect("/suggestions");
});
app.get("/timeline", (req, res) => {
let username = req.get("X-REPLIT-USER-NAME");
let loginURL = '#';
if(!username || username.length == 0) {
username = "Log In";
loginURL = "/login";
}
console.log("We're in the timeline page [DEBUG]");
res.send(fs.readFileSync(`/${__dirname}/views/timeline.html`).toString().split("{{USERNAME}}").join(username).split("{{LOGIN_URL}}").join(loginURL));
});
app.listen(8080, () => {
console.log("Listening on port 8080.");
});