Add dashboard error handling, seed data, and Docker host Ollama wiring
- Wrap getDashboardSnapshot in try/catch; return JSON 500 instead of crashing - Add prisma/seed.ts with realistic Feb + Mar 2026 data: biweekly $2,850 pay schedule, $2,430 rent, expenses across all 8 categories - Update Dockerfile and backup route for host Ollama runtime Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { getDatabaseBackupFileName, resolveSqliteDatabasePath } from "@/lib/storage";
|
||||
import { getDatabaseBackupFileName } from "@/lib/storage";
|
||||
|
||||
function resolveDbPath(): string {
|
||||
const dbUrl = process.env.DATABASE_URL || "file:./prisma/dev.db";
|
||||
const rawPath = dbUrl.slice("file:".length);
|
||||
if (path.isAbsolute(rawPath)) {
|
||||
return rawPath;
|
||||
}
|
||||
return path.resolve(process.cwd(), rawPath);
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
const filePath = resolveSqliteDatabasePath();
|
||||
const file = await readFile(filePath);
|
||||
try {
|
||||
const dbPath = resolveDbPath();
|
||||
console.error("[backup] resolved path:", dbPath);
|
||||
const file = await readFile(dbPath);
|
||||
console.error("[backup] read bytes:", file.length);
|
||||
|
||||
return new NextResponse(file, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/x-sqlite3",
|
||||
"Content-Disposition": `attachment; filename="${getDatabaseBackupFileName()}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
return new NextResponse(file, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/x-sqlite3",
|
||||
"Content-Disposition": `attachment; filename="${getDatabaseBackupFileName()}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[backup] error:", error);
|
||||
return new NextResponse(String(error), { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ export async function GET(request: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
const dashboard = await getDashboardSnapshot(parsed.data.month);
|
||||
return NextResponse.json(dashboard);
|
||||
try {
|
||||
const dashboard = await getDashboardSnapshot(parsed.data.month);
|
||||
return NextResponse.json(dashboard);
|
||||
} catch (error) {
|
||||
console.error("[dashboard] snapshot error:", error);
|
||||
return NextResponse.json({ error: "Could not load the dashboard." }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user