-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
index.js
111 lines (99 loc) · 3.96 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
import express from 'express';
import http from 'node:http';
import path from 'node:path';
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { createBareServer } from "@tomphttp/bare-server-node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
import wisp from "wisp-server-node";
import request from '@cypress/request';
import chalk from 'chalk';
import packageJson from './package.json' assert { type: 'json' };
const __dirname = path.resolve();
const server = http.createServer();
const bareServer = createBareServer('/seal/');
const app = express(server);
const version = packageJson.version;
const discord = 'https://discord.gg/unblocking';
const routes = [
{ route: '/mastery', file: './static/loader.html' },
{ route: '/apps', file: './static/apps.html' },
{ route: '/gms', file: './static/gms.html' },
{ route: '/lessons', file: './static/agloader.html' },
{ route: '/info', file: './static/info.html' },
{ route: '/mycourses', file: './static/loading.html' }
];
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use(express.static(path.join(__dirname, 'static')));
app.use("/uv/", express.static(uvPath));
app.use("/epoxy/", express.static(epoxyPath));
app.use("/baremux/", express.static(baremuxPath));
routes.forEach(({ route, file }) => {
app.get(route, (req, res) => {
res.sendFile(path.join(__dirname, file));
});
});
app.get('/student', (req, res) => {
res.redirect('/portal');
});
app.get('/worker.js', (req, res) => {
request('https://cdn.surfdoge.pro/worker.js', (error, response, body) => {
if (!error && response.statusCode === 200) {
res.setHeader('Content-Type', 'text/javascript');
res.send(body);
} else {
res.status(500).send('Error fetching worker script');
}
});
});
app.use((req, res) => {
res.statusCode = 404;
res.sendFile(path.join(__dirname, './static/404.html'));
});
server.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
} else socket.end();
});
server.on('listening', () => {
console.log(chalk.bgBlue.white.bold(` Welcome to Doge V4, user! `) + '\n');
console.log(chalk.cyan('-----------------------------------------------'));
console.log(chalk.green(' 🌟 Status: ') + chalk.bold('Active'));
console.log(chalk.green(' 🌍 Port: ') + chalk.bold(chalk.yellow(server.address().port)));
console.log(chalk.green(' 🕒 Time: ') + chalk.bold(new Date().toLocaleTimeString()));
console.log(chalk.cyan('-----------------------------------------------'));
console.log(chalk.magenta('📦 Version: ') + chalk.bold(version));
console.log(chalk.magenta('🔗 URL: ') + chalk.underline('http://localhost:' + server.address().port));
console.log(chalk.cyan('-----------------------------------------------'));
console.log(chalk.blue('💬 Discord: ') + chalk.underline(discord));
console.log(chalk.cyan('-----------------------------------------------'));
});
function shutdown(signal) {
console.log(chalk.bgRed.white.bold(` Shutting Down (Signal: ${signal}) `) + '\n');
console.log(chalk.red('-----------------------------------------------'));
console.log(chalk.yellow(' 🛑 Status: ') + chalk.bold('Shutting Down'));
console.log(chalk.yellow(' 🕒 Time: ') + chalk.bold(new Date().toLocaleTimeString()));
console.log(chalk.red('-----------------------------------------------'));
console.log(chalk.blue(' Performing graceful exit...'));
server.close(() => {
console.log(chalk.blue(' Doge has been closed.'));
process.exit(0);
});
}
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));
server.listen({
port: 8000,
});