29 lines
726 B
TypeScript
29 lines
726 B
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { sse } from "@/lib/realtime/sse";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
async function getDeploymentVersion() {
|
|
if (process.env.NODE_ENV === "development") return "DEV";
|
|
|
|
try {
|
|
const version = await readFile(path.join(process.cwd(), ".version"), "utf8");
|
|
return version.trim() || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function GET(request: Request) {
|
|
const version = await getDeploymentVersion();
|
|
if (!version) {
|
|
return new Response("Deployment version unavailable", { status: 503 });
|
|
}
|
|
|
|
return sse.active.stream({
|
|
signal: request.signal,
|
|
motd: { event: "version", data: version },
|
|
});
|
|
}
|