Realtime frontend dashboard
Unanswered
Broad-snouted Caiman posted this in #help-forum
Broad-snouted CaimanOP
I'm trying to make a real-time frontend dashboard for my game telemetry.
I have a route at
Inside the
What I have right now is a page with two cards that fetch the current server and player count.
What I want is, whenever a new server calls the connect endpoint, the servers value in the frontend is replaced with the new server count.
The way I used to do this was having a backend server using express that had the same endpoints, and a WebSocket, and the frontend would just connect to the WebSocket and receive the updates.
Having two different projects, and having to have providers, and everything being client components, having to fetch initial values, etc... just felt really clunky, and I'm hoping there is a better way to do this.
I have a route at
api/server/[id]/connect that game servers call when they start running.Inside the
route.ts, it just adds a new server to a class with a list of servers.What I have right now is a page with two cards that fetch the current server and player count.
export default function Home() {
return (
<main>
<div className={"p-4 mx-auto max-w-7xl"}>
<div className={"grid grid-cols-1 sm:grid-cols-2 gap-4"}>
<OverviewCard title={"Servers"} value={serverStoreManager.getServerCount()} />
<OverviewCard title={"Players"} value={serverStoreManager.getPlayerCount()} />
</div>
</div>
</main>
);
}What I want is, whenever a new server calls the connect endpoint, the servers value in the frontend is replaced with the new server count.
The way I used to do this was having a backend server using express that had the same endpoints, and a WebSocket, and the frontend would just connect to the WebSocket and receive the updates.
Having two different projects, and having to have providers, and everything being client components, having to fetch initial values, etc... just felt really clunky, and I'm hoping there is a better way to do this.
7 Replies
Madeiran sardinella
So, you want to fetch initial values to use in the server rendering?
Why don't you do it all in the client?
Why don't you do it all in the client?
@Madeiran sardinella So, you want to fetch initial values to use in the server rendering?
Why don't you do it all in the client?
Broad-snouted CaimanOP
I was using websockets on the client but it was really cluttered and I was wondering if there was a better way
Using sever component magic or smth
Madeiran sardinella
Ok, I don't know if it'll work but maybe you can have a websocket in an API route and revalidate the path every time that receives a request. I'm really not sure if that refresh the page, but it's the first that comes to mind
@Madeiran sardinella Ok, I don't know if it'll work but maybe you can have a websocket in an API route and revalidate the path every time that receives a request. I'm really not sure if that refresh the page, but it's the first that comes to mind
Broad-snouted CaimanOP
Don’t need to refresh the page, but the websocket in a route sounds interesting. Could you share a link?
Madeiran sardinella
There are some examples in google with pages router not with app router, although, look at this maybe it's useful as inspiration:
https://socket.io/how-to/use-with-nextjs
https://socket.io/how-to/use-with-nextjs
Remember that there is no problem with have both app and pages routes if you need