Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
154 lines (138 loc) · 6.15 KB
/
Copy pathindex.js
File metadata and controls
154 lines (138 loc) · 6.15 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import express from "express";
import http from "node:http";
import cors from "cors";
import chalk from "chalk";
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
import { server as wisp, logging } from "@mercuryworkshop/wisp-js/server";
import gradient from "gradient-string";
import fs from "node:fs";
import Git from "./srv/git.js";
import { execSync } from "child_process";
import router from "./srv/router.js";
import path from "node:path";
const git_url = (await execSync("git config --get remote.origin.url").toString());
const commit = await execSync("git rev-parse HEAD").toString();
const git = new Git(git_url);
const server = http.createServer();
const app = express();
const packageInfo = JSON.parse(fs.readFileSync("package.json"));
const PORT = process.env.PORT || 8080;
logging.set_level(logging.ERROR);
wisp.options.dns_method = "resolve";
wisp.options.dns_servers = ["1.1.1.3", "1.0.0.3"];
wisp.options.dns_result_order = "ipv4first";
wisp.options.wisp_version = 2;
wisp.options.wisp_motd = "WISP server";
try {
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(express.static(path.join(process.cwd(), "public/static/")));
app.use("/epoxy/", express.static(epoxyPath));
app.use("/@/", express.static(uvPath));
app.use("/libcurl/", express.static(libcurlPath));
app.use("/baremux/", express.static(baremuxPath)); // proxy stuff
app.use("/", router);
server.on("request", (req, res) => {
app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});
server.on("listening", async () => {
const address = server.address();
const theme = chalk.hex("#630aba");
const ddx = {
1: "#8b0ab8",
2: "#630aba",
3: "#665e72",
4: "#1c1724"
}; //credits to nebula for the gradient design idea on the title.
const gitColor = chalk.hex("#00ff95");
const host = chalk.hex("#0d52bd");
const startupText = `
██████╗ █████╗ ██╗ ██╗██████╗ ██████╗ ███████╗ █████╗ ███╗ ███╗ ██╗ ██╗
██╔══██╗██╔══██╗╚██╗ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔══██╗████╗ ████║ ╚██╗██╔╝
██║ ██║███████║ ╚████╔╝ ██║ ██║██████╔╝█████╗ ███████║██╔████╔██║ ╚███╔╝
██║ ██║██╔══██║ ╚██╔╝ ██║ ██║██╔══██╗██╔══╝ ██╔══██║██║╚██╔╝██║ ██╔██╗
██████╔╝██║ ██║ ██║ ██████╔╝██║ ██║███████╗██║ ██║██║ ╚═╝ ██║ ██╔╝ ██╗
╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
`;
console.log(gradient(Object.values(ddx)).multiline(startupText));
console.log(
gitColor("Last Updated on: "),
chalk.whiteBright((await git.fetchLastCommitDate()) + " "),
gitColor("Commit:"),
chalk.whiteBright(await git.fetchLastCommitID()),
gitColor("Up to Date:"),
chalk.whiteBright(
commit === (await git.fetchLastCommitID()) ? "✅" : "❌",
),
);
console.log(
theme("Version: "),
chalk.whiteBright("v" + packageInfo.version),
);
let dns = false;
if (process.env.REPL_SLUG && process.env.REPL_OWNER) {
var method = "Replit";
var extLink = ` https://${process.env.REPL_SLUG}.${process.env.REPL_OWNER}.repl.co`;
} else if (
process.env.CODESPACE_NAME &&
process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN
) {
var method = "Github Codespaces";
var extLink = ` https://${process.env.CODESPACE_NAME}-${PORT}.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`;
} else if (
process.env.HOSTNAME &&
process.env.GITPOD_WORKSPACE_CLUSTER_HOST
) {
var method = "Gitpod";
var extLink = ` https://${PORT}-${process.env.HOSTNAME}.${process.env.GITPOD_WORKSPACE_CLUSTER_HOST}`;
} else if (
process.env.VERCEL &&
process.env.VERCEL_PROJECT_PRODUCTION_URL
) {
var method = "Vercel";
var extLink = ` https://${VERCEL_PROJECT_PRODUCTION_URL}`;
} else if (process.env.RENDER && process.env.RENDER_EXTERNAL_HOSTNAME) {
var method = "Render";
var extLink = ` https://${RENDER_EXTERNAL_HOSTNAME}`;
} else if (process.env.KOYEB_APP_NAME && process.env.KOYEB_PUBLIC_DOMAIN) {
var method = "Koyeb";
var extLink = ` https://${KOYEB_PUBLIC_DOMAIN}`;
} else {
var method = "Custom (DNS Deploy?)";
dns = true;
}
console.log(theme("🌐 Deployment Method: "), chalk.whiteBright(method));
console.log(host("🔗 Deployment Entrypoints: "));
console.log(
` ${chalk.bold(host("Local System IPv4:"))} http://localhost:${PORT}`,
);
console.log(
` ${chalk.bold(host("Local System IPv6:"))} http://${address.family === "IPv6" ? `[${address.address}]` : address.address}:${PORT}`,
);
if (dns !== true)
console.log(` ${chalk.bold(host(method + ":"))} ${extLink}`);
});
server.listen({ port: PORT });
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
server.setMaxListeners(0);
function shutdown() {
console.log("SIGTERM signal received: closing HTTP server");
server.close(() => {
console.log("HTTP server closed");
server.close();
process.exit(1);
});
}
} catch (err) {
console.log(chalk.redBright(`Error starting DayDreamX: ${err}`));
}