Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/api/contact/route.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 });
}
}
2 changes: 2 additions & 0 deletions app/api/get-involved/families/route.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 3 additions & 1 deletion app/api/get-involved/students/route.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -11,4 +13,4 @@ export async function GET() {



}
}
2 changes: 2 additions & 0 deletions app/api/home/route.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 3 additions & 1 deletion app/api/news/thumbnails/route.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 });
}
}
4 changes: 3 additions & 1 deletion app/api/research/publications/route.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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 });
}
}
4 changes: 3 additions & 1 deletion app/research/topics/page.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -81,4 +83,4 @@ export default async function ResearchTopicsPage() {
</section>
</main>
);
}
}
2 changes: 2 additions & 0 deletions app/team/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex items-center gap-4 mt-4 mb-4">
Expand Down
43 changes: 29 additions & 14 deletions lib/cosmic.ts
Original file line number Diff line number Diff line change
@@ -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<typeof createBucketClient>, {
get(_target, prop, receiver) {
return Reflect.get(createCosmicClient(), prop, receiver);
},
});

export const hasCosmicWriteKey = () => Boolean(process.env.COSMIC_WRITE_KEY);
8 changes: 6 additions & 2 deletions services/CosmicServices.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { error } from "console";
import { cosmic } from "../lib/cosmic";
import { cosmic, hasCosmicWriteKey } from "../lib/cosmic";
import {
TeamMember,
NewsPost,
Expand Down Expand Up @@ -481,6 +480,11 @@ class CosmicServices {
submitContactForm = async (
submission: ContactFormSubmission,
): Promise<boolean> => {
if (!hasCosmicWriteKey()) {
console.error("Missing COSMIC_WRITE_KEY environment variable");
return false;
}

try {
await cosmic.objects.insertOne({
type: "messages",
Expand Down
Loading