From 148a1450f5a685c436dca39961f57ac88aa35b96 Mon Sep 17 00:00:00 2001 From: braiancalot Date: Sat, 23 Nov 2024 09:54:02 -0300 Subject: [PATCH 1/2] build: add `swr` lib --- package-lock.json | 23 ++++++++++++++++++++++- package.json | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e2c78c..6e1696d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "node-pg-migrate": "7.6.1", "pg": "8.12.0", "react": "18.3.1", - "react-dom": "18.3.1" + "react-dom": "18.3.1", + "swr": "2.2.5" }, "devDependencies": { "@commitlint/cli": "19.4.0", @@ -10332,6 +10333,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swr": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz", + "integrity": "sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==", + "dependencies": { + "client-only": "^0.0.1", + "use-sync-external-store": "^1.2.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -10678,6 +10691,14 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz", + "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index f02f289..a1493a2 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "node-pg-migrate": "7.6.1", "pg": "8.12.0", "react": "18.3.1", - "react-dom": "18.3.1" + "react-dom": "18.3.1", + "swr": "2.2.5" }, "devDependencies": { "@commitlint/cli": "19.4.0", From 2f16fe4a11017211bdd77644556203e337913fd2 Mon Sep 17 00:00:00 2001 From: braiancalot Date: Sat, 23 Nov 2024 09:56:20 -0300 Subject: [PATCH 2/2] feat: add `status` page --- pages/status/index.js | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pages/status/index.js diff --git a/pages/status/index.js b/pages/status/index.js new file mode 100644 index 0000000..8879248 --- /dev/null +++ b/pages/status/index.js @@ -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 ( + <> +

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
Ultima atualização: {updatedAtText}
; +} + +function Status() { + const { isLoading, data } = useSwr("/api/v1/status", fetchAPI, { + refreshInterval: 2000, + }); + + let databaseStatus; + + if (isLoading) return
Carregando...
; + + if (!data?.dependencies?.database) + return
Não foi possível obter as informações.
; + + databaseStatus = data.dependencies.database; + + return ( + <> +
Versão do Banco de Dados: {databaseStatus.version}
+
Número máximo de conexões: {databaseStatus.max_connections}
+
Conexões abertas: {databaseStatus.opened_connections}
+ + ); +}