Fix version API to read version.txt directly

This commit is contained in:
Hördle Bot
2025-11-25 10:22:12 +01:00
parent 54af256e91
commit 3e647cd44b
2 changed files with 205 additions and 2 deletions

View File

@@ -1,14 +1,32 @@
import { NextResponse } from 'next/server';
import { execSync } from 'child_process';
import { readFileSync, existsSync } from 'fs';
import { join } from 'path';
export async function GET() {
try {
// First check if version is set via environment variable (Docker build)
// First check if version file exists (Docker deployment)
// Try both /app/version.txt (Docker) and ./version.txt (local)
const versionPaths = [
'/app/version.txt',
join(process.cwd(), 'version.txt')
];
for (const versionFilePath of versionPaths) {
if (existsSync(versionFilePath)) {
const version = readFileSync(versionFilePath, 'utf-8').trim();
if (version && version !== 'unknown') {
return NextResponse.json({ version });
}
}
}
// Fallback: check environment variable
if (process.env.APP_VERSION) {
return NextResponse.json({ version: process.env.APP_VERSION });
}
// Try to get the git tag/version
// Fallback: try to get from git (local development)
let version = 'dev';
try {