beginning of mobile site

This commit is contained in:
metacryst
2025-12-01 03:07:55 -06:00
parent fcf0b4b08a
commit daa4182778
50 changed files with 1377 additions and 43 deletions

View File

@@ -6,6 +6,7 @@ const fs = require('fs');
const chalk = require('chalk');
const moment = require('moment');
const path = require('path');
const useragent = require("express-useragent");
import "./util.js"
import Socket from './ws/ws.js'
@@ -112,12 +113,13 @@ class Server {
let privateSite = () => {
let filePath;
let platformFolder = req.useragent.isMobile ? "mobile" : "desktop"
if(url.startsWith("/_")) {
filePath = path.join(this.UIPath, url);
} else if(url.includes("75820185")) {
filePath = path.join(this.UIPath, "site", url.split("75820185")[1]);
filePath = path.join(this.UIPath, platformFolder, url.split("75820185")[1]);
} else {
filePath = path.join(this.UIPath, "site", "index.html");
filePath = path.join(this.UIPath, platformFolder, "index.html");
}
res.sendFile(filePath);
@@ -134,10 +136,10 @@ class Server {
const formattedDate = moment().format('M.D');
const formattedTime = moment().format('h:mma');
if(req.url.includes("/api/")) {
console.logclean(chalk.blue(` ${req.method} ${req.url} | ${formattedDate} ${formattedTime}`));
console.log(chalk.blue(` ${req.method} ${req.url} | ${formattedDate} ${formattedTime}`));
} else {
if(req.url === "/")
console.logclean(chalk.gray(` ${req.method} ${req.url} | ${formattedDate} ${formattedTime}`));
console.log(chalk.gray(` ${req.method} ${req.url} | ${formattedDate} ${formattedTime}`));
}
next();
}
@@ -146,9 +148,9 @@ class Server {
const originalSend = res.send;
res.send = function (body) {
if(res.statusCode >= 400) {
console.logclean(chalk.blue( `<-${chalk.red(res.statusCode)}- ${req.method} ${req.url} | ${chalk.red(body)}`));
console.log(chalk.blue( `<-${chalk.red(res.statusCode)}- ${req.method} ${req.url} | ${chalk.red(body)}`));
} else {
console.logclean(chalk.blue(`<-${res.statusCode}- ${req.method} ${req.url}`));
console.log(chalk.blue(`<-${res.statusCode}- ${req.method} ${req.url}`));
}
originalSend.call(this, body);
};
@@ -164,6 +166,7 @@ class Server {
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(useragent.express());
app.use(this.logRequest);
app.use(this.logResponse);
@@ -176,16 +179,16 @@ class Server {
global.Socket = new Socket(server);
const PORT = 3003;
server.listen(PORT, () => {
console.logclean("\n")
console.logclean(chalk.yellow("*************** Hyperia ***************"))
console.logclean(chalk.yellowBright(`Server is running on port ${PORT}: http://localhost`));
console.logclean(chalk.yellow("***************************************"))
console.logclean("\n")
console.log("\n")
console.log(chalk.yellow("*************** Hyperia ***************"))
console.log(chalk.yellowBright(`Server is running on port ${PORT}: http://localhost`));
console.log(chalk.yellow("***************************************"))
console.log("\n")
});
process.on('SIGINT', async () => {
console.logclean(chalk.red('Closing server...'));
console.logclean(chalk.green('Database connection closed.'));
console.log(chalk.red('Closing server...'));
console.log(chalk.green('Database connection closed.'));
process.exit(0);
});
@@ -193,31 +196,4 @@ class Server {
}
}
const _log = console.log;
console.logclean = function (...args) {
_log.call(console, ...args);
}
// console.log = function (...args) {
// // Get the caller location
// const stack = new Error().stack.split("\n")[2];
// const match = stack.match(/(\/.*:\d+:\d+)/);
// let location = match ? match[1] : "unknown";
// // Remove CWD prefix
// while (location.startsWith("/")) {
// location = location.slice(1);
// }
// location = "/" + location
// let cwd = process.cwd();
// if (location.startsWith(cwd)) {
// location = location.slice(cwd.length);
// if (location.startsWith("/")) location = location.slice(1);
// }
// _log.call(console, `[${location}]`, ...args);
// };
const server = new Server()