feat : Add version settings and API endpoint to display application version

This commit is contained in:
Yash 2025-12-25 00:21:10 +05:30
parent 860e6390f1
commit 612b00179b
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,35 @@
import { readFile } from 'fs/promises';
import { join } from 'path';
import { parseRequest } from '@/lib/request';
import { json } from '@/lib/response';
let cachedVersion: string | null = null;
async function getVersion(): Promise<string> {
if (cachedVersion) {
return cachedVersion;
}
try {
const packageJsonPath = join(process.cwd(), 'package.json');
const data = await readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(data);
cachedVersion = packageJson.version || 'unknown';
} catch (error) {
cachedVersion = 'unknown';
}
return cachedVersion;
}
export async function GET(request: Request) {
const { error } = await parseRequest(request, null, { skipAuth: true });
if (error) {
return error();
}
const version = await getVersion();
return json({ version });
}