forked from The-Ghost-Network/Ghost-Node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
118 lines (98 loc) · 2.42 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { createBareServer } from "@tomphttp/bare-server-node";
import http from "node:http";
import express from "express"
import g from "./server_lib/games.mjs"
import a from "./server_lib/apps.mjs"
const bare = createBareServer("/bare/");
const server = http.createServer();
const PORT = 8080;
const app = express();
const __dirname = process.cwd();
server.on('request', (req, res) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
app(req, res);
}
});
server.on('upgrade', (req, socket, head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
app.use(express.static(__dirname + "/public"));
app.get("/", (req, res) => {
res.sendFile("/public/index.html", { root: __dirname });
});
app.get("/s/", (req, res) => {
res.sendFile("/public/settings.html", { root: __dirname });
});
app.get("/w/", (req, res) => {
res.sendFile("/public/browser.html", { root: __dirname });
});
app.get("/b/", (req, res) => {
res.sendFile("/public/browser.html", { root: __dirname });
});
app.get("/c/", (req, res) => {
res.sendFile("/public/ag.html", { root: __dirname });
});
app.get("/a/", (req, res) => {
res.sendFile("/public/algebra.html", { root: __dirname });
});
app.get("/q/", (req, res) => {
res.sendFile("/public/g.html", { root: __dirname });
});
var sg = [];
var sa = [];
function getrand() {
sg.splice(0, sg.length);
for (var i = 0; i < 8; i++) {
var rg = g.length;
var random = Math.floor(Math.random() * rg);
if (!sg.includes(g[random])) {
sg.push(g[random]);
} else {
i--;
}
}
};
function getrandapps() {
sa.splice(0, sa.length);
for (var i = 0; i < 8; i++) {
var ra = a.length;
var random = Math.floor(Math.random() * ra);
if (!sa.includes(a[random])) {
sa.push(a[random]);
} else {
i--;
}
}
};
setInterval(getrand, 500000);
setInterval(getrandapps, 500000);
getrand();
getrandapps();
app.get("/api/g/v1/", (req, res) => {
res.json(g)
});
app.get('/api/rg/v1/', (req, res) => {
res.json(sg)
});
app.get('/api/a/v1/', (req, res) => {
res.json(a)
});
app.get('/api/ra/v1/', (req, res) => {
res.json(sa)
});
server.listen(PORT);
server.on("listening", () => {
console.log("Ghost Is On http://localhost:" + PORT);
});
server.on("SIGTERM", () => {
debug("SIGTERM signal received: closing HTTP server");
server.close(() => {
debug("HTTP server closed");
});
});