import { NextResponse } from 'next/server'; import { execSync } from 'child_process'; export async function GET() { try { // Try to get the git tag/version let version = 'dev'; try { // First try to get the exact tag if we're on a tagged commit version = execSync('git describe --tags --exact-match 2>/dev/null', { encoding: 'utf-8', cwd: process.cwd() }).trim(); } catch { try { // If not on a tag, get the latest tag with commit info version = execSync('git describe --tags --always 2>/dev/null', { encoding: 'utf-8', cwd: process.cwd() }).trim(); } catch { // If git is not available or no tags exist, try to get commit hash try { const hash = execSync('git rev-parse --short HEAD 2>/dev/null', { encoding: 'utf-8', cwd: process.cwd() }).trim(); version = `dev-${hash}`; } catch { // Fallback to just 'dev' if git is not available version = 'dev'; } } } return NextResponse.json({ version }); } catch (error) { console.error('Error getting version:', error); return NextResponse.json({ version: 'unknown' }); } }