Skip to content

Commit

Permalink
feat: add status page
Browse files Browse the repository at this point in the history
  • Loading branch information
braiancalot committed Nov 23, 2024
1 parent 148a145 commit 2f16fe4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pages/status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import useSwr from "swr";

async function fetchAPI(key) {
const response = await fetch(key);
const responseBody = await response.json();
return responseBody;
}

export default function StatusPage() {
return (
<>
<h1>Status</h1>
<UpdatedAt />
<br />
<Status />
</>
);
}

function UpdatedAt() {
const { isLoading, data } = useSwr("/api/v1/status", fetchAPI, {
refreshInterval: 2000,
});

let updatedAtText = "Carregando...";

if (!isLoading && data) {
updatedAtText = new Date(data.updated_at).toLocaleString("pt-BR");
}

return <div>Ultima atualização: {updatedAtText}</div>;
}

function Status() {
const { isLoading, data } = useSwr("/api/v1/status", fetchAPI, {
refreshInterval: 2000,
});

let databaseStatus;

if (isLoading) return <div>Carregando...</div>;

if (!data?.dependencies?.database)
return <div>Não foi possível obter as informações.</div>;

databaseStatus = data.dependencies.database;

return (
<>
<div>Versão do Banco de Dados: {databaseStatus.version}</div>
<div>Número máximo de conexões: {databaseStatus.max_connections}</div>
<div>Conexões abertas: {databaseStatus.opened_connections}</div>
</>
);
}

0 comments on commit 2f16fe4

Please sign in to comment.