-
Notifications
You must be signed in to change notification settings - Fork 380
/
index.js
61 lines (49 loc) · 2.97 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
import createBareServer from "@tomphttp/bare-server-node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
import http from "node:http";
import serveStatic from "serve-static";
import connect from "connect";
import Buffy from "./buffy.js";
console.log(`
██████╗ ██╗ ██╗███████╗███████╗██╗ ██╗
██╔══██╗██║ ██║██╔════╝██╔════╝╚██╗ ██╔╝
██████╔╝██║ ██║█████╗ █████╗ ╚████╔╝
██╔══██╗██║ ██║██╔══╝ ██╔══╝ ╚██╔╝
██████╔╝╚██████╔╝██║ ██║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
`);
// The following message MAY NOT be removed
console.log("Incognito-Lite\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n");
const proxy = new Buffy({
url: "https://amethystnetwork-dev.github.io/Incognito/static",
validateStatus: (status) => status !== 404
}); // Proxy the static folder
const gs = new Buffy({
url: "https://amethystnetwork-dev.github.io/Incognito/gsource",
validateStatus: (status) => status !== 404
}); // Proxy the game files
const app = connect();
const bare = createBareServer("/bare/");
const server = http.createServer();
app.use((req, res, next) => {
if(bare.shouldRoute(req)) bare.routeRequest(req, res); else next();
});
app.use("/service", (req, res) => res.end("OK"));
app.use("/source", (req, res, next) => gs.request(req, res, next));
app.use((req, res, next) => proxy.request(req, res, next));
app.use("/uv", serveStatic(uvPath));
server.on("request", app);
server.on("upgrade", (req, socket, head) => {
if(bare.shouldRoute(req, socket, head)) bare.routeUpgrade(req, socket, head); else socket.end();
});
server.on("listening", () => {
const addr = server.address();
console.log(`Server running on port ${addr.port}`);
console.log("");
console.log("You can now view it in your browser.");
/* Code for listing IPS from website-aio */
console.log(`Local: http://${addr.family === "IPv6" ? `[${addr.address}]` : addr.address}:${addr.port}`);
try { console.log(`On Your Network: http://${address.ip()}:${addr.port}`); } catch (err) {/* Can't find LAN interface */};
if(process.env.REPL_SLUG && process.env.REPL_OWNER) console.log(`Replit: https://${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`);
});
server.listen({ port: (process.env.PORT || 8080) })