Files
vibn-frontend/app/api/projects/prewarm/route.ts
Mark Henderson 6f79a88abd fix(gitea-bot): add write:organization scope so bot can create repos
Without this the bot PAT 403s on POST /orgs/{org}/repos, which is
the single most important operation — creating new project repos
inside the workspace's Gitea org.

Made-with: Cursor
2026-04-21 11:05:55 -07:00

29 lines
980 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { authSession } from "@/lib/auth/session-server";
import { prewarmWorkspace } from '@/lib/cloud-run-workspace';
/**
* POST /api/projects/prewarm
* Body: { urls: string[] }
*
* Fires warm-up requests to Cloud Run workspace URLs so containers
* are running by the time the user clicks "Open IDE". Server-side
* to avoid CORS issues with run.app domains.
*/
export async function POST(req: NextRequest) {
const session = await authSession();
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { urls } = await req.json() as { urls: string[] };
if (!Array.isArray(urls) || urls.length === 0) {
return NextResponse.json({ warmed: 0 });
}
// Fire all prewarm pings in parallel — intentionally not awaited
Promise.allSettled(urls.map(url => prewarmWorkspace(url))).catch(() => {});
return NextResponse.json({ warmed: urls.length });
}