diff --git a/src/app/api/server/route.ts b/src/app/api/server/route.ts index bbafd6d..207247e 100644 --- a/src/app/api/server/route.ts +++ b/src/app/api/server/route.ts @@ -1,7 +1,10 @@ import axios, { HttpStatusCode } from "axios"; import { NextResponse } from "next/server"; -import { servers } from "../servers/servers"; +import { PORT, servers } from "../servers/servers"; import validate from "../auth/auth"; +import Service from "@/types/service"; + +const allServices: { [key: string]: Service[] } = {}; export async function GET(request: Request) { const { searchParams } = new URL(request.url); @@ -26,10 +29,12 @@ export async function GET(request: Request) { const server = servers.data[parseInt(index)]; - const apps = await axios.get(`http://${server.ip}:8080/apps`, {params: {auth: 'my-key'}}); + axios.get(`http://${server.ip}:${PORT}/apps`, {params: {auth: 'my-key'}}).then((apps) => { + allServices[parseInt(index)] = apps.data; + }); return NextResponse.json({ message: "ok", - apps: apps.data, + apps: allServices[parseInt(index)] || [], }); } diff --git a/src/app/api/servers/servers.ts b/src/app/api/servers/servers.ts index 148593b..c9bc31e 100644 --- a/src/app/api/servers/servers.ts +++ b/src/app/api/servers/servers.ts @@ -2,6 +2,8 @@ import Server, { ServerAPI } from "@/types/server"; import Data from "../data"; import axios from "axios"; +export const PORT = 63774; + export const useServer = (server: ServerAPI, index: number) => { const interval = setInterval(() => { if (deletes.has(index) || !currentServers[index]) { @@ -9,7 +11,7 @@ export const useServer = (server: ServerAPI, index: number) => { interval.close(); return; } - axios.get(`http://${server.ip}:8080/`, {params: {auth: 'my-key'}}).then(({data}) => { + axios.get(`http://${server.ip}:${PORT}/`, {params: {auth: 'my-key'}}).then(({data}) => { if (data.status) { currentServers[index].status = data.status; } @@ -25,7 +27,9 @@ export const useServer = (server: ServerAPI, index: number) => { if (data.network) { currentServers[index].network = data.network; } + currentServers[index].status = 'online'; }).catch((e) => { + currentServers[index].status = 'offline'; console.error(e.data); }) }, 2000); diff --git a/src/app/dashboard/server.tsx b/src/app/dashboard/server.tsx index 0d59c53..7cd8ff0 100644 --- a/src/app/dashboard/server.tsx +++ b/src/app/dashboard/server.tsx @@ -24,6 +24,7 @@ import { import { Label } from "@/components/ui/label"; import { Progress } from "@/components/ui/progress"; import Session from "@/lib/session"; +import { cn } from "@/lib/utils"; import Server from "@/types/server"; import { Cpu, @@ -130,12 +131,12 @@ export default function ServerComponent({