fix clan badge ( primary_guild), add timezone api, move robots to public/custom support, move to atums/echo for logging instead
All checks were successful
Code quality checks / biome (push) Successful in 9s
All checks were successful
Code quality checks / biome (push) Successful in 9s
This commit is contained in:
parent
eb2bec6649
commit
3cb3b76a2b
13 changed files with 269 additions and 123 deletions
|
@ -15,6 +15,8 @@ BADGE_API_URL=http://localhost:8081
|
||||||
# Required if you want to enable reviews from reviewdb
|
# Required if you want to enable reviews from reviewdb
|
||||||
REVIEW_DB=true
|
REVIEW_DB=true
|
||||||
|
|
||||||
|
#Timezone api url, aka: https://git.creations.works/creations/timezoneDB
|
||||||
|
TIMEZONE_API_URL=
|
||||||
|
|
||||||
# https://www.steamgriddb.com/api/v2, if you want games to have images
|
# https://www.steamgriddb.com/api/v2, if you want games to have images
|
||||||
STEAMGRIDDB_API_KEY=steamgrid_api_key
|
STEAMGRIDDB_API_KEY=steamgrid_api_key
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ bun.lock
|
||||||
logs/
|
logs/
|
||||||
.vscode/
|
.vscode/
|
||||||
robots.txt
|
robots.txt
|
||||||
|
public/custom
|
||||||
|
|
|
@ -63,8 +63,8 @@ cp .env.example .env
|
||||||
| `LANYARD_INSTANCE` | Endpoint of the Lanyard instance |
|
| `LANYARD_INSTANCE` | Endpoint of the Lanyard instance |
|
||||||
| `BADGE_API_URL` | Badge API URL ([badgeAPI](https://git.creations.works/creations/badgeAPI)) |
|
| `BADGE_API_URL` | Badge API URL ([badgeAPI](https://git.creations.works/creations/badgeAPI)) |
|
||||||
| `REVIEW_DB` | Enables showing reviews from reviewdb on user pages |
|
| `REVIEW_DB` | Enables showing reviews from reviewdb on user pages |
|
||||||
|
| `TIMEZONE_API_URL` | Enables showing times from [timezoneDB](https://git.creations.works/creations/timezoneDB) |
|
||||||
| `STEAMGRIDDB_API_KEY` | SteamGridDB API key for fetching game icons |
|
| `STEAMGRIDDB_API_KEY` | SteamGridDB API key for fetching game icons |
|
||||||
| `ROBOTS_FILE` | If there it uses the file in /robots.txt route, requires a valid path |
|
|
||||||
|
|
||||||
#### Optional Lanyard KV Variables (per-user customization)
|
#### Optional Lanyard KV Variables (per-user customization)
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ These can be defined in Lanyard's KV store to customize the page:
|
||||||
| `css` | URL to a css to change styles on the page, no import or require allowed |
|
| `css` | URL to a css to change styles on the page, no import or require allowed |
|
||||||
| `optout` | Allows users to stop sharing there profile on the website (`true` / `false`) |
|
| `optout` | Allows users to stop sharing there profile on the website (`true` / `false`) |
|
||||||
| `reviews` | Enables reviews from reviewdb (`true` / `false`) |
|
| `reviews` | Enables reviews from reviewdb (`true` / `false`) |
|
||||||
|
| `timezone`| Enables the showing of the current time from the timezone db API (`true` / `false`) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { resolve } from "node:path";
|
import { echo } from "@atums/echo";
|
||||||
import { logger } from "@creations.works/logger";
|
|
||||||
|
|
||||||
const environment: Environment = {
|
const environment: Environment = {
|
||||||
port: Number.parseInt(process.env.PORT || "8080", 10),
|
port: Number.parseInt(process.env.PORT || "8080", 10),
|
||||||
|
@ -22,16 +21,14 @@ const reviewDb = {
|
||||||
url: "https://manti.vendicated.dev/api/reviewdb",
|
url: "https://manti.vendicated.dev/api/reviewdb",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const timezoneAPIUrl: string | null = process.env.TIMEZONE_API_URL || null;
|
||||||
|
|
||||||
const badgeApi: string | null = process.env.BADGE_API_URL || null;
|
const badgeApi: string | null = process.env.BADGE_API_URL || null;
|
||||||
const steamGridDbKey: string | undefined = process.env.STEAMGRIDDB_API_KEY;
|
const steamGridDbKey: string | undefined = process.env.STEAMGRIDDB_API_KEY;
|
||||||
|
|
||||||
const plausibleScript: string | null =
|
const plausibleScript: string | null =
|
||||||
process.env.PLAUSIBLE_SCRIPT_HTML?.trim() || null;
|
process.env.PLAUSIBLE_SCRIPT_HTML?.trim() || null;
|
||||||
|
|
||||||
const robotstxtPath: string | null = process.env.ROBOTS_FILE
|
|
||||||
? resolve(process.env.ROBOTS_FILE)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
function verifyRequiredVariables(): void {
|
function verifyRequiredVariables(): void {
|
||||||
const requiredVariables = [
|
const requiredVariables = [
|
||||||
"HOST",
|
"HOST",
|
||||||
|
@ -46,7 +43,7 @@ function verifyRequiredVariables(): void {
|
||||||
for (const key of requiredVariables) {
|
for (const key of requiredVariables) {
|
||||||
const value = process.env[key];
|
const value = process.env[key];
|
||||||
if (value === undefined || value.trim() === "") {
|
if (value === undefined || value.trim() === "") {
|
||||||
logger.error(`Missing or empty environment variable: ${key}`);
|
echo.error(`Missing or empty environment variable: ${key}`);
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,9 +58,9 @@ export {
|
||||||
lanyardConfig,
|
lanyardConfig,
|
||||||
redisTtl,
|
redisTtl,
|
||||||
reviewDb,
|
reviewDb,
|
||||||
|
timezoneAPIUrl,
|
||||||
badgeApi,
|
badgeApi,
|
||||||
steamGridDbKey,
|
steamGridDbKey,
|
||||||
plausibleScript,
|
plausibleScript,
|
||||||
robotstxtPath,
|
|
||||||
verifyRequiredVariables,
|
verifyRequiredVariables,
|
||||||
};
|
};
|
||||||
|
|
39
logger.json
Normal file
39
logger.json
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"directory": "logs",
|
||||||
|
"level": "debug",
|
||||||
|
"disableFile": false,
|
||||||
|
|
||||||
|
"rotate": true,
|
||||||
|
"maxFiles": 3,
|
||||||
|
|
||||||
|
"console": true,
|
||||||
|
"consoleColor": true,
|
||||||
|
|
||||||
|
"dateFormat": "yyyy-MM-dd HH:mm:ss.SSS",
|
||||||
|
"timezone": "local",
|
||||||
|
|
||||||
|
"silent": false,
|
||||||
|
|
||||||
|
"pattern": "{color:gray}{pretty-timestamp}{reset} {color:levelColor}[{level-name}]{reset} {color:gray}({reset}{file-name}:{color:blue}{line}{reset}:{color:blue}{column}{color:gray}){reset} {data}",
|
||||||
|
"levelColor": {
|
||||||
|
"debug": "blue",
|
||||||
|
"info": "green",
|
||||||
|
"warn": "yellow",
|
||||||
|
"error": "red",
|
||||||
|
"fatal": "red"
|
||||||
|
},
|
||||||
|
|
||||||
|
"customPattern": "{color:gray}{pretty-timestamp}{reset} {color:tagColor}[{tag}]{reset} {color:contextColor}({context}){reset} {data}",
|
||||||
|
"customColors": {
|
||||||
|
"GET": "green",
|
||||||
|
"POST": "blue",
|
||||||
|
"PUT": "yellow",
|
||||||
|
"DELETE": "red",
|
||||||
|
"PATCH": "cyan",
|
||||||
|
"HEAD": "magenta",
|
||||||
|
"OPTIONS": "white",
|
||||||
|
"TRACE": "gray"
|
||||||
|
},
|
||||||
|
|
||||||
|
"prettyPrint": true
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@creations.works/logger": "^1.0.3",
|
"@atums/echo": "^1.0.3",
|
||||||
"marked": "^15.0.7"
|
"marked": "^15.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -995,3 +995,37 @@ ul {
|
||||||
height: 16px;
|
height: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* timezone display */
|
||||||
|
|
||||||
|
.timezone-wrapper {
|
||||||
|
position: fixed;
|
||||||
|
top: 1rem;
|
||||||
|
right: 1rem;
|
||||||
|
background-color: var(--card-bg);
|
||||||
|
color: var(--text-color);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
|
||||||
|
z-index: 100;
|
||||||
|
user-select: none;
|
||||||
|
opacity: 0.85;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timezone-wrapper:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timezone-label {
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-right: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.timezone-label {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ const userId = head?.dataset.userId;
|
||||||
const activityProgressMap = new Map();
|
const activityProgressMap = new Map();
|
||||||
|
|
||||||
const reviewURL = head?.dataset.reviewDb;
|
const reviewURL = head?.dataset.reviewDb;
|
||||||
|
const timezoneApiUrl = head?.dataset.timezoneApi;
|
||||||
let instanceUri = head?.dataset.instanceUri;
|
let instanceUri = head?.dataset.instanceUri;
|
||||||
let badgeURL = head?.dataset.badgeUrl;
|
let badgeURL = head?.dataset.badgeUrl;
|
||||||
let socket;
|
let socket;
|
||||||
|
@ -209,6 +210,60 @@ async function populateReviews(userId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function populateTimezone(userId) {
|
||||||
|
if (!userId || !timezoneApiUrl) return;
|
||||||
|
|
||||||
|
let currentTimezone = null;
|
||||||
|
|
||||||
|
async function fetchTimezone() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`${timezoneApiUrl}/get?id=${encodeURIComponent(userId)}`,
|
||||||
|
);
|
||||||
|
if (!res.ok) throw new Error("Failed to fetch timezone");
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
if (!json || typeof json.timezone !== "string") return;
|
||||||
|
|
||||||
|
currentTimezone = json.timezone;
|
||||||
|
updateTime();
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to populate timezone", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTime() {
|
||||||
|
if (!currentTimezone) return;
|
||||||
|
|
||||||
|
const timezoneEl = document.querySelector(".timezone-value");
|
||||||
|
if (!timezoneEl) return;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const time24 = now.toLocaleTimeString("en-GB", {
|
||||||
|
timeZone: currentTimezone,
|
||||||
|
hour12: false,
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
});
|
||||||
|
|
||||||
|
const time12 = now.toLocaleTimeString("en-US", {
|
||||||
|
timeZone: currentTimezone,
|
||||||
|
hour12: true,
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
});
|
||||||
|
|
||||||
|
timezoneEl.textContent = time24;
|
||||||
|
timezoneEl.title = `${time12} (${currentTimezone})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchTimezone();
|
||||||
|
setInterval(updateTime, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
function setupReviewScrollObserver(userId) {
|
function setupReviewScrollObserver(userId) {
|
||||||
const sentinel = document.createElement("div");
|
const sentinel = document.createElement("div");
|
||||||
sentinel.className = "review-scroll-sentinel";
|
sentinel.className = "review-scroll-sentinel";
|
||||||
|
@ -593,6 +648,14 @@ async function updatePresence(initialData) {
|
||||||
setupReviewScrollObserver(userId);
|
setupReviewScrollObserver(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kv.timezone !== "false" && userId && timezoneApiUrl) {
|
||||||
|
populateTimezone(userId);
|
||||||
|
const timezoneEl = document.querySelector(".timezone-value");
|
||||||
|
if (timezoneEl) {
|
||||||
|
timezoneEl.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const platform = {
|
const platform = {
|
||||||
mobile: data.active_on_discord_mobile,
|
mobile: data.active_on_discord_mobile,
|
||||||
web: data.active_on_discord_web,
|
web: data.active_on_discord_web,
|
||||||
|
@ -755,7 +818,7 @@ function updateClanBadge(data) {
|
||||||
const userInfoInner = document.querySelector(".user-info-inner");
|
const userInfoInner = document.querySelector(".user-info-inner");
|
||||||
if (!userInfoInner) return;
|
if (!userInfoInner) return;
|
||||||
|
|
||||||
const clan = data?.discord_user?.clan;
|
const clan = data?.discord_user?.primary_guild;
|
||||||
if (!clan || !clan.tag || !clan.identity_guild_id || !clan.badge) return;
|
if (!clan || !clan.tag || !clan.identity_guild_id || !clan.badge) return;
|
||||||
|
|
||||||
const existing = userInfoInner.querySelector(".clan-badge");
|
const existing = userInfoInner.querySelector(".clan-badge");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { serverHandler } from "@/server";
|
import { serverHandler } from "@/server";
|
||||||
|
import { echo } from "@atums/echo";
|
||||||
import { verifyRequiredVariables } from "@config/environment";
|
import { verifyRequiredVariables } from "@config/environment";
|
||||||
import { logger } from "@creations.works/logger";
|
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
verifyRequiredVariables();
|
verifyRequiredVariables();
|
||||||
|
@ -8,7 +8,7 @@ async function main(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((error: Error) => {
|
main().catch((error: Error) => {
|
||||||
logger.error(["Error initializing the server:", error]);
|
echo.error({ message: "Error initializing the server", error });
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
lanyardConfig,
|
lanyardConfig,
|
||||||
plausibleScript,
|
plausibleScript,
|
||||||
reviewDb,
|
reviewDb,
|
||||||
|
timezoneAPIUrl,
|
||||||
} from "@config/environment";
|
} from "@config/environment";
|
||||||
import { file } from "bun";
|
import { file } from "bun";
|
||||||
|
|
||||||
|
@ -33,6 +34,10 @@ async function handler(request: ExtendedRequest): Promise<Response> {
|
||||||
head.setAttribute("data-review-db", reviewDb.url);
|
head.setAttribute("data-review-db", reviewDb.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timezoneAPIUrl) {
|
||||||
|
head.setAttribute("data-timezone-api", timezoneAPIUrl);
|
||||||
|
}
|
||||||
|
|
||||||
if (plausibleScript) {
|
if (plausibleScript) {
|
||||||
head.append(plausibleScript, { html: true });
|
head.append(plausibleScript, { html: true });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { environment, robotstxtPath } from "@config/environment";
|
import { echo } from "@atums/echo";
|
||||||
import { logger } from "@creations.works/logger";
|
import { environment } from "@config/environment";
|
||||||
import {
|
import {
|
||||||
type BunFile,
|
type BunFile,
|
||||||
FileSystemRouter,
|
FileSystemRouter,
|
||||||
|
@ -43,16 +43,14 @@ class ServerHandler {
|
||||||
`http://127.0.0.1:${server.port}`,
|
`http://127.0.0.1:${server.port}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
logger.info(`Server running at ${accessUrls[0]}`);
|
echo.info(`Server running at ${accessUrls[0]}`);
|
||||||
logger.info(`Access via: ${accessUrls[1]} or ${accessUrls[2]}`, {
|
echo.info(`Access via: ${accessUrls[1]} or ${accessUrls[2]}`);
|
||||||
breakLine: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logRoutes();
|
this.logRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private logRoutes(): void {
|
private logRoutes(): void {
|
||||||
logger.info("Available routes:");
|
echo.info("Available routes:");
|
||||||
|
|
||||||
const sortedRoutes: [string, string][] = Object.entries(
|
const sortedRoutes: [string, string][] = Object.entries(
|
||||||
this.router.routes,
|
this.router.routes,
|
||||||
|
@ -61,7 +59,7 @@ class ServerHandler {
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const [path, filePath] of sortedRoutes) {
|
for (const [path, filePath] of sortedRoutes) {
|
||||||
logger.info(`Route: ${path}, File: ${filePath}`);
|
echo.info(`Route: ${path}, File: ${filePath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +88,14 @@ class ServerHandler {
|
||||||
headers: { "Content-Type": contentType },
|
headers: { "Content-Type": contentType },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`File not found: ${filePath}`);
|
echo.warn(`File not found: ${filePath}`);
|
||||||
response = new Response("Not Found", { status: 404 });
|
response = new Response("Not Found", { status: 404 });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error([`Error serving static file: ${pathname}`, error as Error]);
|
echo.error({
|
||||||
|
message: `Error serving static file: ${pathname}`,
|
||||||
|
error: error as Error,
|
||||||
|
});
|
||||||
response = new Response("Internal Server Error", { status: 500 });
|
response = new Response("Internal Server Error", { status: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,16 +108,23 @@ class ServerHandler {
|
||||||
response: Response,
|
response: Response,
|
||||||
ip: string | undefined,
|
ip: string | undefined,
|
||||||
): void {
|
): void {
|
||||||
logger.custom(
|
const pathname = new URL(request.url).pathname;
|
||||||
`[${request.method}]`,
|
|
||||||
`(${response.status})`,
|
const ignoredStartsWith: string[] = ["/public"];
|
||||||
[
|
const ignoredPaths: string[] = ["/favicon.ico"];
|
||||||
|
|
||||||
|
if (
|
||||||
|
ignoredStartsWith.some((prefix) => pathname.startsWith(prefix)) ||
|
||||||
|
ignoredPaths.includes(pathname)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo.custom(`${request.method}`, `${response.status}`, [
|
||||||
request.url,
|
request.url,
|
||||||
`${(performance.now() - request.startPerf).toFixed(2)}ms`,
|
`${(performance.now() - request.startPerf).toFixed(2)}ms`,
|
||||||
ip || "unknown",
|
ip || "unknown",
|
||||||
],
|
]);
|
||||||
"90",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleRequest(
|
private async handleRequest(
|
||||||
|
@ -139,29 +147,21 @@ class ServerHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathname: string = new URL(request.url).pathname;
|
const pathname: string = new URL(request.url).pathname;
|
||||||
if (pathname === "/robots.txt" && robotstxtPath) {
|
|
||||||
try {
|
|
||||||
const file: BunFile = Bun.file(robotstxtPath);
|
|
||||||
|
|
||||||
if (await file.exists()) {
|
const baseDir = resolve("public/custom");
|
||||||
const fileContent: ArrayBuffer = await file.arrayBuffer();
|
const customPath = resolve(baseDir, pathname.slice(1));
|
||||||
const contentType: string = file.type || "text/plain";
|
|
||||||
|
|
||||||
response = new Response(fileContent, {
|
if (!customPath.startsWith(baseDir)) {
|
||||||
headers: { "Content-Type": contentType },
|
return new Response("Forbidden", { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const customFile = Bun.file(customPath);
|
||||||
|
if (await customFile.exists()) {
|
||||||
|
const content = await customFile.arrayBuffer();
|
||||||
|
const type = customFile.type || "application/octet-stream";
|
||||||
|
response = new Response(content, {
|
||||||
|
headers: { "Content-Type": type },
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
logger.warn(`File not found: ${robotstxtPath}`);
|
|
||||||
response = new Response("Not Found", { status: 404 });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error([
|
|
||||||
`Error serving robots.txt: ${robotstxtPath}`,
|
|
||||||
error as Error,
|
|
||||||
]);
|
|
||||||
response = new Response("Internal Server Error", { status: 500 });
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logRequest(extendedRequest, response, ip);
|
this.logRequest(extendedRequest, response, ip);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,10 @@ class ServerHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logger.error([`Error handling route ${request.url}:`, error as Error]);
|
echo.error({
|
||||||
|
message: `Error handling route ${request.url}`,
|
||||||
|
error: error,
|
||||||
|
});
|
||||||
|
|
||||||
response = Response.json(
|
response = Response.json(
|
||||||
{
|
{
|
||||||
|
@ -291,9 +294,11 @@ class ServerHandler {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logRequest(extendedRequest, response, ip);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverHandler: ServerHandler = new ServerHandler(
|
const serverHandler: ServerHandler = new ServerHandler(
|
||||||
environment.port,
|
environment.port,
|
||||||
environment.host,
|
environment.host,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="description" content="View real-time Discord presence, activities, and badges with open-source integration." />
|
<meta name="description"
|
||||||
|
content="View real-time Discord presence, activities, and badges with open-source integration." />
|
||||||
<meta name="color-scheme" content="dark" />
|
<meta name="color-scheme" content="dark" />
|
||||||
|
|
||||||
<title>Discord Presence</title>
|
<title>Discord Presence</title>
|
||||||
|
@ -19,20 +21,16 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<a
|
<a href="https://git.creations.works/creations/profilePage" target="_blank" rel="noopener noreferrer"
|
||||||
href="https://git.creations.works/creations/profilePage"
|
title="View source code on Forgejo">
|
||||||
target="_blank"
|
<img class="open-source-logo" src="/public/assets/forgejo_logo.svg" alt="Forgejo open-source logo"
|
||||||
rel="noopener noreferrer"
|
style="opacity: 0.5" loading="lazy" />
|
||||||
title="View source code on Forgejo"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
class="open-source-logo"
|
|
||||||
src="/public/assets/forgejo_logo.svg"
|
|
||||||
alt="Forgejo open-source logo"
|
|
||||||
style="opacity: 0.5"
|
|
||||||
loading="lazy"
|
|
||||||
/>
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<div class="timezone-wrapper" id="timezone-wrapper" aria-label="Timezone Information">
|
||||||
|
<span class="timezone-label">Users Time:</span>
|
||||||
|
<span class="timezone-value"></span>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
@ -71,4 +69,5 @@
|
||||||
|
|
||||||
<script src="/public/js/index.js" type="module"></script>
|
<script src="/public/js/index.js" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -1,27 +1,27 @@
|
||||||
import { logger } from "@creations.works/logger";
|
import { echo } from "@atums/echo";
|
||||||
import type { ServerWebSocket } from "bun";
|
import type { ServerWebSocket } from "bun";
|
||||||
|
|
||||||
class WebSocketHandler {
|
class WebSocketHandler {
|
||||||
public handleMessage(ws: ServerWebSocket, message: string): void {
|
public handleMessage(ws: ServerWebSocket, message: string): void {
|
||||||
logger.info(`WebSocket received: ${message}`);
|
echo.info(`WebSocket received: ${message}`);
|
||||||
try {
|
try {
|
||||||
ws.send(`You said: ${message}`);
|
ws.send(`You said: ${message}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(["WebSocket send error", error as Error]);
|
echo.error({ message: "WebSocket send error", error: error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleOpen(ws: ServerWebSocket): void {
|
public handleOpen(ws: ServerWebSocket): void {
|
||||||
logger.info("WebSocket connection opened.");
|
echo.info("WebSocket connection opened.");
|
||||||
try {
|
try {
|
||||||
ws.send("Welcome to the WebSocket server!");
|
ws.send("Welcome to the WebSocket server!");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(["WebSocket send error", error as Error]);
|
echo.error({ message: "WebSocket send error", error: error });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleClose(ws: ServerWebSocket, code: number, reason: string): void {
|
public handleClose(ws: ServerWebSocket, code: number, reason: string): void {
|
||||||
logger.warn(`WebSocket closed with code ${code}, reason: ${reason}`);
|
echo.warn(`WebSocket closed with code ${code}, reason: ${reason}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue