Update server (with types)

This commit is contained in:
MotorTruck1221 2024-03-04 00:57:42 -07:00
parent be8dc47f29
commit 289cd7ccec
No known key found for this signature in database
GPG key ID: 06901A625432AC21
3 changed files with 86 additions and 10 deletions

View file

@ -19,6 +19,7 @@
"@nebula-services/bare-server-node": "2.0.1-patch.1",
"@nebula-services/dynamic": "0.7.2-patch.2",
"@titaniumnetwork-dev/ultraviolet": "^3.0.0",
"@types/express": "^4.17.21",
"chalk": "^5.3.0",
"classnames": "^2.5.1",
"compression": "^1.7.4",
@ -41,7 +42,8 @@
"react-icons": "^4.12.0",
"react-toastify": "^9.1.3",
"tsx": "^4.7.1",
"wisp-server-node": "^1.0.1"
"wisp-server-node": "^1.0.1",
"ws": "^8.16.0"
},
"devDependencies": {
"@preact/preset-vite": "^2.8.1",

72
pnpm-lock.yaml generated
View file

@ -29,6 +29,9 @@ dependencies:
'@titaniumnetwork-dev/ultraviolet':
specifier: ^3.0.0
version: 3.0.0
'@types/express':
specifier: ^4.17.21
version: 4.17.21
chalk:
specifier: ^5.3.0
version: 5.3.0
@ -98,6 +101,9 @@ dependencies:
wisp-server-node:
specifier: ^1.0.1
version: 1.0.1
ws:
specifier: ^8.16.0
version: 8.16.0
devDependencies:
'@preact/preset-vite':
@ -1136,6 +1142,19 @@ packages:
dev: false
optional: true
/@types/body-parser@1.19.5:
resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==}
dependencies:
'@types/connect': 3.4.38
'@types/node': 20.11.24
dev: false
/@types/connect@3.4.38:
resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
dependencies:
'@types/node': 20.11.24
dev: false
/@types/estree@0.0.46:
resolution: {integrity: sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==}
dev: false
@ -1143,6 +1162,24 @@ packages:
/@types/estree@1.0.5:
resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==}
/@types/express-serve-static-core@4.17.43:
resolution: {integrity: sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==}
dependencies:
'@types/node': 20.11.24
'@types/qs': 6.9.12
'@types/range-parser': 1.2.7
'@types/send': 0.17.4
dev: false
/@types/express@4.17.21:
resolution: {integrity: sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==}
dependencies:
'@types/body-parser': 1.19.5
'@types/express-serve-static-core': 4.17.43
'@types/qs': 6.9.12
'@types/serve-static': 1.15.5
dev: false
/@types/glob@7.2.0:
resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
requiresBuild: true
@ -1152,10 +1189,22 @@ packages:
dev: false
optional: true
/@types/http-errors@2.0.4:
resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==}
dev: false
/@types/json-schema@7.0.15:
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
dev: true
/@types/mime@1.3.5:
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
dev: false
/@types/mime@3.0.4:
resolution: {integrity: sha512-iJt33IQnVRkqeqC7PzBHPTC6fDlRNRW8vjrgqtScAhrmMwe8c4Eo7+fUGTa+XdWrpEgpyKWMYmi2dIwMAYRzPw==}
dev: false
/@types/minimatch@5.1.2:
resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==}
requiresBuild: true
@ -1169,6 +1218,14 @@ packages:
undici-types: 5.26.5
dev: false
/@types/qs@6.9.12:
resolution: {integrity: sha512-bZcOkJ6uWrL0Qb2NAWKa7TBU+mJHPzhx9jjLL1KHF+XpzEcR7EXHvjbHlGtR/IsP1vyPrehuS6XqkmaePy//mg==}
dev: false
/@types/range-parser@1.2.7:
resolution: {integrity: sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==}
dev: false
/@types/resolve@0.0.8:
resolution: {integrity: sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==}
dependencies:
@ -1179,6 +1236,21 @@ packages:
resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==}
dev: true
/@types/send@0.17.4:
resolution: {integrity: sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==}
dependencies:
'@types/mime': 1.3.5
'@types/node': 20.11.24
dev: false
/@types/serve-static@1.15.5:
resolution: {integrity: sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==}
dependencies:
'@types/http-errors': 2.0.4
'@types/mime': 3.0.4
'@types/node': 20.11.24
dev: false
/@types/uuid@9.0.8:
resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==}
dev: false

View file

@ -9,7 +9,8 @@ import path from "path";
import fs from "fs";
import cookieParser from "cookie-parser";
import wisp from "wisp-server-node";
import { Socket } from "net";
import { Request, Response } from "express";
import { Socket, Head } from "ws";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@ -47,7 +48,7 @@ app.use(
app.use(cookieParser());
// Congratulations! Masqr failed to validate, this is either your first visit or you're a FRAUD
async function MasqFail(req, res) {
async function MasqFail(req: Request, res: Response) {
if (!req.headers.host) {
// no bitch still using HTTP/1.0 go away
return;
@ -124,7 +125,7 @@ async function MasqFail(req, res) {
app.use(express.static("dist"));
app.get("/search=:query", async (req, res) => {
app.get("/search=:query", async (req: Request, res: Response) => {
const { query } = req.params;
const response = await fetch(
@ -142,7 +143,7 @@ const server = createServer();
const bare = createBareServer("/bare/");
server.on("request", (req, res) => {
server.on("request", (req: Request, res: Response) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else if (shouldRouteRh(req)) {
@ -152,13 +153,14 @@ server.on("request", (req, res) => {
}
});
server.on("upgrade", (req, socket, head) => {
server.on("upgrade", (req: Request, socket: Socket, head: Head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else if (shouldRouteRh(req)) {
routeRhUpgrade(req, socket, head);
} else {
wisp.routeRequest(req, socket as Socket, head);
}
else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
}
});
@ -170,11 +172,11 @@ function shouldRouteRh(req) {
);
}
function routeRhRequest(req, res) {
function routeRhRequest(req: Request, res: Response) {
rh.emit("request", req, res);
}
function routeRhUpgrade(req, socket, head) {
function routeRhUpgrade(req: Request, socket: Socket, head: Head) {
rh.emit("upgrade", req, socket, head);
}