mirror of
https://git.moonleay.net/Websites/liljudd-website.git
synced 2025-07-25 11:02:04 +02:00
Fix: Using bigint and added backend testing
This commit is contained in:
parent
ed6195e1e2
commit
89507f8412
20 changed files with 830 additions and 292 deletions
|
@ -1,8 +1,14 @@
|
|||
import { createMiddleware } from "@solidjs/start/middleware";
|
||||
import { Session, User, verifyRequestOrigin } from "lucia";
|
||||
import colors from "colors";
|
||||
import fs from "fs";
|
||||
import { verifyRequestOrigin } from "lucia";
|
||||
import { appendHeader, getCookie, getHeader } from "vinxi/http";
|
||||
import { lucia } from "./lib/auth";
|
||||
|
||||
colors.enable();
|
||||
|
||||
let started: boolean = false;
|
||||
|
||||
export default createMiddleware({
|
||||
onRequest: async (event) => {
|
||||
if (event.nativeEvent.node.req.method !== "GET") {
|
||||
|
@ -43,12 +49,52 @@ export default createMiddleware({
|
|||
event.nativeEvent.context.session = session;
|
||||
event.nativeEvent.context.user = user;
|
||||
},
|
||||
});
|
||||
onBeforeResponse: async (event, response) => {
|
||||
let consoleLog = "",
|
||||
fileLog = "";
|
||||
|
||||
declare module "h3" {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
interface H3EventContext {
|
||||
user: User | null;
|
||||
session: Session | null;
|
||||
}
|
||||
}
|
||||
if (!started) {
|
||||
try {
|
||||
await fs.promises.mkdir("log");
|
||||
console.log("Created 'log' Folder.");
|
||||
} catch {}
|
||||
started = true;
|
||||
}
|
||||
|
||||
const currentDate = new Date();
|
||||
const year = currentDate.getFullYear();
|
||||
const month = String(currentDate.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(currentDate.getDate()).padStart(2, "0");
|
||||
const hours = String(currentDate.getHours()).padStart(2, "0");
|
||||
const minutes = String(currentDate.getMinutes()).padStart(2, "0");
|
||||
const seconds = String(currentDate.getSeconds()).padStart(2, "0");
|
||||
|
||||
// Create a short and numeric representation
|
||||
const date = `[${year}-${month}-${day}_${hours}:${minutes}:${seconds}]`;
|
||||
const xForwardedFor = event.request.headers.get("x-forwarded-for");
|
||||
const ip = (xForwardedFor || "127.0.0.1, 192.168.178.1").split(",");
|
||||
const route = event.request.url;
|
||||
const frontend = !new URL(event.request.url).pathname.startsWith("/api");
|
||||
const method = frontend ? "Frontend" : event.request.method;
|
||||
const code =
|
||||
(response.body as Response | undefined)?.status ?? event.response.status;
|
||||
consoleLog += [
|
||||
date,
|
||||
ip[0].yellow,
|
||||
method,
|
||||
code,
|
||||
route?.green,
|
||||
event.nativeEvent.context.user?.discord_id.rainbow,
|
||||
].join(" ");
|
||||
fileLog += [
|
||||
date,
|
||||
ip[0],
|
||||
method,
|
||||
code,
|
||||
route,
|
||||
event.nativeEvent.context.user?.discord_id,
|
||||
].join(" ");
|
||||
await fs.promises.appendFile("log/log.txt", fileLog + "\n");
|
||||
console.log(consoleLog);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue