This commit is contained in:
1 parent
e85e4d74ea
commit
2e4ed76121
378 files changed
+22404
-20686
No files matched your search
@@ -1,53 +1,53 @@
|
||||
import net from 'node:net'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { env } from '@/env'
|
||||
import { withAdmin } from '@/lib/api-handler'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import net from "node:net";
|
||||
import { NextResponse } from "next/server";
|
||||
import { env } from "@/env";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
function checkRcon(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const host = env.RCON_HOST
|
||||
const port = env.RCON_PORT
|
||||
const host = env.RCON_HOST;
|
||||
const port = env.RCON_PORT;
|
||||
|
||||
const socket = new net.Socket()
|
||||
const socket = new net.Socket();
|
||||
const timeout = setTimeout(() => {
|
||||
socket.destroy()
|
||||
resolve(false)
|
||||
}, 3000)
|
||||
socket.destroy();
|
||||
resolve(false);
|
||||
}, 3000);
|
||||
|
||||
socket.connect(port, host, () => {
|
||||
clearTimeout(timeout)
|
||||
socket.destroy()
|
||||
resolve(true)
|
||||
})
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
socket.on('error', () => {
|
||||
clearTimeout(timeout)
|
||||
socket.destroy()
|
||||
resolve(false)
|
||||
})
|
||||
})
|
||||
socket.on("error", () => {
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const GET = withAdmin({ permission: PERMS.DEVOPS_VIEW }, async () => {
|
||||
// DB health
|
||||
let dbOk = false
|
||||
let dbLatency = 0
|
||||
let dbOk = false;
|
||||
let dbLatency = 0;
|
||||
try {
|
||||
const start = Date.now()
|
||||
await prisma.$queryRaw`SELECT 1`
|
||||
dbLatency = Date.now() - start
|
||||
dbOk = true
|
||||
const start = Date.now();
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
dbLatency = Date.now() - start;
|
||||
dbOk = true;
|
||||
} catch {
|
||||
dbOk = false
|
||||
dbOk = false;
|
||||
}
|
||||
|
||||
// Emulator health (RCON TCP check)
|
||||
const emulator = await checkRcon()
|
||||
const emulator = await checkRcon();
|
||||
|
||||
// Online users
|
||||
const onlineUsers = await prisma.user.count({ where: { online: '1' } })
|
||||
const onlineUsers = await prisma.user.count({ where: { online: "1" } });
|
||||
|
||||
return NextResponse.json({
|
||||
database: dbOk,
|
||||
@@ -55,5 +55,5 @@ export const GET = withAdmin({ permission: PERMS.DEVOPS_VIEW }, async () => {
|
||||
emulator,
|
||||
onlineUsers,
|
||||
timestamp: new Date().toISOString(),
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user