feat: add deployment reload controls
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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 },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user