Files
sofa/instrumentation.ts
T
jakeandClaude Opus 4.6 ee723e41d6 Add TMDB image caching pipeline and resolve image URLs server-side
Introduce a local disk cache for TMDB images served through a proxy API
route (/api/images/[...path]), eliminating direct client-side CDN
dependencies. Images are cached by category (posters, backdrops, stills,
logos) and served with immutable cache headers.

Move all tmdbImageUrl() calls from client components to API routes and
server components so clients receive ready-to-use URLs. This removes the
need to expose TMDB_IMAGE_BASE_URL and IMAGE_CACHE_ENABLED via
next.config.ts env block. The landing page is split into a server
wrapper (app/page.tsx) and client component (components/landing-page.tsx).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 13:10:17 -05:00

41 lines
1.2 KiB
TypeScript

export async function onRequestError() {
// Required by Next.js instrumentation
}
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
// Run database migrations on startup
if (process.env.NODE_ENV === "production") {
const { runMigrations } = await import("@/lib/db/migrate");
await runMigrations();
// Ensure image cache directories exist
const { ensureImageDirs, imageCacheEnabled } = await import(
"@/lib/services/image-cache"
);
if (imageCacheEnabled()) {
ensureImageDirs();
}
const { initJobs } = await import("@/lib/jobs/init");
initJobs();
// Graceful shutdown — stop jobs and close DB on container stop
const { scheduler } = await import("@/lib/jobs/scheduler");
const { client } = await import("@/lib/db/client");
const shutdown = () => {
console.log("[shutdown] Stopping scheduler...");
scheduler.stop();
console.log("[shutdown] Closing database...");
client.close();
console.log("[shutdown] Clean shutdown complete");
process.exit(0);
};
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);
}
}
}