Initial commit: page-manager Next.js app with Coolify deploy support

Replace Vercel-specific infra (Cron, Blob) with self-hosted equivalents
for deployment to Coolify: in-container cron scheduler
(scripts/cron-runner.mjs) and disk-based upload storage served via
/api/uploads/[...path]. Add Dockerfile, .dockerignore, and /api/health
for container health checks.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
chaloemphong
2026-11-22 11:52:17 +07:00
commit 9d32552457
155 changed files with 22174 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import { NextResponse } from "next/server";
import { safeFacebookErrorMessage, UserFacingError, FacebookApiError } from "@/lib/facebook/client";
export async function readJson(req: Request): Promise<Record<string, unknown>> {
const body = await req.json().catch(() => null);
return body && typeof body === "object" ? (body as Record<string, unknown>) : {};
}
export const str = (v: unknown): string => (typeof v === "string" ? v : "");
export const optStr = (v: unknown): string | null => (typeof v === "string" && v.trim() ? v.trim() : null);
/** Maps thrown errors to a safe JSON response: UserFacingError → 400, Graph → 502, other → 500. */
export function errorResponse(e: unknown, context: string): NextResponse {
const message = safeFacebookErrorMessage(e, context);
const status = e instanceof UserFacingError ? 400 : e instanceof FacebookApiError ? 502 : 500;
return NextResponse.json({ error: message }, { status });
}
/**
* 200 HTML page that meta-refreshes to `path`. OAuth callbacks arrive as a
* cross-site navigation, so a 302 onward would still be cross-site and the
* SameSite=Strict session cookie would not be sent; a navigation started by
* this page is same-site. `path` must already be a validated same-origin path.
*/
export function htmlRedirect(path: string): Response {
const safe = path.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const html = `<!doctype html><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=${safe}"><title>กำลังกลับสู่ระบบ…</title><p style="font-family:system-ui;padding:24px">กำลังกลับสู่ระบบ… <a href="${safe}">ไปต่อ</a></p>`;
return new Response(html, { headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" } });
}
/** Cron routes authenticate with `Authorization: Bearer ${CRON_SECRET}` (Vercel Cron sends it). */
export function cronAuthorized(req: Request): boolean {
const secret = process.env.CRON_SECRET;
return Boolean(secret) && req.headers.get("authorization") === `Bearer ${secret}`;
}