From 9e2c0e9c25ef46f3406edbfeb427683e7b1d3b36 Mon Sep 17 00:00:00 2001 From: Vincent <07xuvi@gmail.com> Date: Wed, 3 Jun 2026 23:21:59 -0400 Subject: [PATCH 1/2] Redeploy commit From ac98da342ee4a98595c93d8f16fa066cde8581f1 Mon Sep 17 00:00:00 2001 From: xuvi7 <07xuvi@gmail.com> Date: Sat, 13 Jun 2026 02:00:48 -0400 Subject: [PATCH 2/2] fix --- .github/workflows/preview.yaml | 4 +++ .github/workflows/production.yaml | 4 +++ app/api/contact/route.ts | 4 ++- app/api/get-involved/families/route.ts | 2 ++ app/api/get-involved/students/route.ts | 4 ++- app/api/home/route.ts | 2 ++ app/api/news/thumbnails/route.ts | 4 ++- app/api/research/publications/route.ts | 4 ++- app/research/topics/page.tsx | 4 ++- app/team/page.tsx | 2 ++ lib/cosmic.ts | 43 +++++++++++++++++--------- services/CosmicServices.ts | 8 +++-- 12 files changed, 64 insertions(+), 21 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index ec528a8..732c543 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -17,6 +17,10 @@ jobs: - uses: actions/checkout@v4 - name: Install Vercel CLI run: npm install --global vercel@latest + - name: Verify required environment variables + run: | + test -n "$COSMIC_BUCKET_SLUG" || (echo "::error::Missing COSMIC_BUCKET_SLUG GitHub secret" && exit 1) + test -n "$COSMIC_READ_KEY" || (echo "::error::Missing COSMIC_READ_KEY GitHub secret" && exit 1) - name: Pull Vercel Environment Information run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - name: Build Project Artifacts diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index b207f8c..e87c24e 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -17,6 +17,10 @@ jobs: - uses: actions/checkout@v4 - name: Install Vercel CLI run: npm install --global vercel@latest + - name: Verify required environment variables + run: | + test -n "$COSMIC_BUCKET_SLUG" || (echo "::error::Missing COSMIC_BUCKET_SLUG GitHub secret" && exit 1) + test -n "$COSMIC_READ_KEY" || (echo "::error::Missing COSMIC_READ_KEY GitHub secret" && exit 1) - name: Pull Vercel Environment Information run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - name: Build Project Artifacts diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index 58a5d3b..82f544b 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + const cosmicServices = new CosmicServices(); export async function POST(req: Request) { @@ -23,7 +25,7 @@ export async function POST(req: Request) { } return NextResponse.json({ ok: true }); - } catch (error) { + } catch { return NextResponse.json({ error: "Server error" }, { status: 500 }); } } diff --git a/app/api/get-involved/families/route.ts b/app/api/get-involved/families/route.ts index edbff85..1e38c42 100644 --- a/app/api/get-involved/families/route.ts +++ b/app/api/get-involved/families/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + export async function GET() { const cosmic = new CosmicServices(); const data = await cosmic.getFamilyInvolvementPage(); diff --git a/app/api/get-involved/students/route.ts b/app/api/get-involved/students/route.ts index 0b524dc..e764381 100644 --- a/app/api/get-involved/students/route.ts +++ b/app/api/get-involved/students/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + export async function GET() { const cosmic = new CosmicServices(); const data = await cosmic.getStudentInvolvementPage(); @@ -11,4 +13,4 @@ export async function GET() { -} \ No newline at end of file +} diff --git a/app/api/home/route.ts b/app/api/home/route.ts index 3671de4..f23a0af 100644 --- a/app/api/home/route.ts +++ b/app/api/home/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + export async function GET() { const cosmic = new CosmicServices(); const homePage = await cosmic.getHomePage(); diff --git a/app/api/news/thumbnails/route.ts b/app/api/news/thumbnails/route.ts index 54e0865..cbf99d9 100644 --- a/app/api/news/thumbnails/route.ts +++ b/app/api/news/thumbnails/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + const cosmicServices = new CosmicServices(); // GET /api/news/thumbnails?limit=15&page=0 @@ -11,7 +13,7 @@ export async function GET(req: Request) { try { const thumbnails = await cosmicServices.getNewsPostThumbnails(limit, page); return NextResponse.json({ thumbnails }); - } catch (error) { + } catch { return NextResponse.json({ error: "Failed to fetch news thumbnails" }, { status: 500 }); } } diff --git a/app/api/research/publications/route.ts b/app/api/research/publications/route.ts index 3a4e8b2..8ba65c8 100644 --- a/app/api/research/publications/route.ts +++ b/app/api/research/publications/route.ts @@ -1,6 +1,8 @@ import { NextResponse } from "next/server"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + const cosmicServices = new CosmicServices(); export async function GET() { @@ -10,7 +12,7 @@ export async function GET() { return NextResponse.json({ error: "Failed to fetch publications" }, { status: 500 }); } return NextResponse.json({ data }); - } catch (error) { + } catch { return NextResponse.json({ error: "Server error" }, { status: 500 }); } } diff --git a/app/research/topics/page.tsx b/app/research/topics/page.tsx index 68a0845..d2c0144 100644 --- a/app/research/topics/page.tsx +++ b/app/research/topics/page.tsx @@ -1,6 +1,8 @@ import Image from "next/image"; import CosmicServices from "@/services/CosmicServices"; +export const dynamic = "force-dynamic"; + export default async function ResearchTopicsPage() { const cosmic = new CosmicServices(); const data = await cosmic.getResearchTopicsPage(); @@ -81,4 +83,4 @@ export default async function ResearchTopicsPage() { ); -} \ No newline at end of file +} diff --git a/app/team/page.tsx b/app/team/page.tsx index 9a80c17..5390561 100644 --- a/app/team/page.tsx +++ b/app/team/page.tsx @@ -3,6 +3,8 @@ import StaffCard from "@/components/StaffCard"; import UndergradCard from "@/components/UndergradCard"; import { TeamMember } from "@/services/CosmicTypes"; +export const dynamic = "force-dynamic"; + function SectionHeader({ title }: { title: string }) { return (
diff --git a/lib/cosmic.ts b/lib/cosmic.ts index 5d838ce..f047600 100644 --- a/lib/cosmic.ts +++ b/lib/cosmic.ts @@ -1,17 +1,32 @@ import { createBucketClient } from '@cosmicjs/sdk'; -if (!process.env.COSMIC_BUCKET_SLUG) { - throw new Error("Missing COSMIC_BUCKET_SLUG environment variable"); -} -if (!process.env.COSMIC_READ_KEY) { - throw new Error("Missing COSMIC_READ_KEY environment variable"); -} -if (!process.env.COSMIC_WRITE_KEY) { - throw new Error("Missing COSMIC_WRITE_KEY environment variable"); -} - -export const cosmic = createBucketClient({ - bucketSlug: process.env.COSMIC_BUCKET_SLUG, - readKey: process.env.COSMIC_READ_KEY, - writeKey: process.env.COSMIC_WRITE_KEY +const requiredCosmicEnv = ["COSMIC_BUCKET_SLUG", "COSMIC_READ_KEY"] as const; + +export const getMissingCosmicEnv = () => + requiredCosmicEnv.filter((key) => !process.env[key]); + +export const assertCosmicReadEnv = () => { + const missing = getMissingCosmicEnv(); + + if (missing.length > 0) { + throw new Error(`Missing Cosmic environment variable(s): ${missing.join(", ")}`); + } +}; + +const createCosmicClient = () => { + assertCosmicReadEnv(); + + return createBucketClient({ + bucketSlug: process.env.COSMIC_BUCKET_SLUG as string, + readKey: process.env.COSMIC_READ_KEY as string, + writeKey: process.env.COSMIC_WRITE_KEY, + }); +}; + +export const cosmic = new Proxy({} as ReturnType, { + get(_target, prop, receiver) { + return Reflect.get(createCosmicClient(), prop, receiver); + }, }); + +export const hasCosmicWriteKey = () => Boolean(process.env.COSMIC_WRITE_KEY); diff --git a/services/CosmicServices.ts b/services/CosmicServices.ts index 9ae569e..72349e4 100644 --- a/services/CosmicServices.ts +++ b/services/CosmicServices.ts @@ -1,5 +1,4 @@ -import { error } from "console"; -import { cosmic } from "../lib/cosmic"; +import { cosmic, hasCosmicWriteKey } from "../lib/cosmic"; import { TeamMember, NewsPost, @@ -481,6 +480,11 @@ class CosmicServices { submitContactForm = async ( submission: ContactFormSubmission, ): Promise => { + if (!hasCosmicWriteKey()) { + console.error("Missing COSMIC_WRITE_KEY environment variable"); + return false; + } + try { await cosmic.objects.insertOne({ type: "messages",