Fix version API to read version.txt directly
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user