From 39e55a06e849f22e4be1d66a024fd4337f0cc5a1 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 27 Dec 2023 19:55:44 +0500 Subject: [PATCH] Add stats and health endpoints --- src/pages/v1-health.ts | 4 ++++ src/pages/v1-stats.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/pages/v1-health.ts create mode 100644 src/pages/v1-stats.ts diff --git a/src/pages/v1-health.ts b/src/pages/v1-health.ts new file mode 100644 index 000000000..eb09adfd8 --- /dev/null +++ b/src/pages/v1-health.ts @@ -0,0 +1,4 @@ +import { execSync } from 'child_process'; +export async function GET() { + return new Response(JSON.stringify({}), {}); +} diff --git a/src/pages/v1-stats.ts b/src/pages/v1-stats.ts new file mode 100644 index 000000000..681fe6036 --- /dev/null +++ b/src/pages/v1-stats.ts @@ -0,0 +1,31 @@ +import { execSync } from 'child_process'; + +export async function GET() { + const commitHash = execSync('git rev-parse HEAD').toString().trim(); + const commitDate = execSync('git log -1 --format=%cd').toString().trim(); + const commitMessage = execSync('git log -1 --format=%B').toString().trim(); + + const prevCommitHash = execSync('git rev-parse HEAD~1').toString().trim(); + const prevCommitDate = execSync('git log -1 --format=%cd HEAD~1') + .toString() + .trim(); + const prevCommitMessage = execSync('git log -1 --format=%B HEAD~1') + .toString() + .trim(); + + return new Response( + JSON.stringify({ + current: { + hash: commitHash, + date: commitDate, + message: commitMessage, + }, + previous: { + hash: prevCommitHash, + date: prevCommitDate, + message: prevCommitMessage, + }, + }), + {}, + ); +}