Theia rip-out: - Delete app/api/theia-auth/route.ts (Traefik ForwardAuth shim) - Delete app/api/projects/[projectId]/workspace/route.ts and app/api/projects/prewarm/route.ts (Cloud Run Theia provisioning) - Delete lib/cloud-run-workspace.ts and lib/coolify-workspace.ts - Strip provisionTheiaWorkspace + theiaWorkspaceUrl/theiaAppUuid/ theiaError from app/api/projects/create/route.ts response - Remove Theia callbackUrl branch in app/auth/page.tsx - Drop "Open in Theia" button + xterm/Theia PTY copy in build/page.tsx - Drop theiaWorkspaceUrl from deployment/page.tsx Project type - Strip Theia IDE line + theia-code-os from advisor + agent-chat context strings - Scrub Theia mention from lib/auth/workspace-auth.ts comment P5.1 (custom apex domains + DNS): - lib/coolify.ts + lib/opensrs.ts: nameserver normalization, OpenSRS XML auth, Cloud DNS plumbing - scripts/smoke-attach-e2e.ts: full prod GCP + sandbox OpenSRS + prod Coolify smoke covering register/zone/A/NS/PATCH/cleanup In-progress (Justine onboarding/build, MVP setup, agent telemetry): - New (justine)/stories, project (home) layouts, mvp-setup, run, tasks routes + supporting components - Project shell + sidebar + nav refactor for the Stackless palette - Agent session API hardening (sessions, events, stream, approve, retry, stop) + atlas-chat, advisor, design-surfaces refresh - New scripts/sync-db-url-from-coolify.mjs + scripts/prisma-db-push.mjs + docker-compose.local-db.yml for local Prisma workflows - lib/dev-bypass.ts, lib/chat-context-refs.ts, lib/prd-sections.ts - Misc: stories CSS, debug/prisma route, modal-theme, BuildLivePlanPanel Made-with: Cursor
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
/**
|
|
* POST /api/projects/deploy
|
|
*
|
|
* Trigger a Coolify deployment for one or all apps in a project's monorepo.
|
|
*
|
|
* Body: { projectId: string, appName?: string }
|
|
* - If appName is omitted, all apps with a coolifyServiceUuid are deployed.
|
|
*/
|
|
|
|
import { NextResponse } from 'next/server';
|
|
import { authSession } from "@/lib/auth/session-server";
|
|
import { query } from '@/lib/db-postgres';
|
|
import { deployApplication } from '@/lib/coolify';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const session = await authSession();
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const { projectId, appName } = await request.json() as {
|
|
projectId: string;
|
|
appName?: string;
|
|
};
|
|
|
|
if (!projectId) {
|
|
return NextResponse.json({ error: 'projectId is required' }, { status: 400 });
|
|
}
|
|
|
|
const rows = await query<{ data: any }>(
|
|
`SELECT data FROM fs_projects WHERE id = $1 LIMIT 1`,
|
|
[projectId],
|
|
);
|
|
|
|
if (!rows[0]) {
|
|
return NextResponse.json({ error: 'Project not found' }, { status: 404 });
|
|
}
|
|
|
|
const projectData = rows[0].data;
|
|
|
|
if (projectData.userId !== session.user.id && projectData.workspace !== session.user.email?.split('@')[0]) {
|
|
// Allow if email matches workspace owner — loose check
|
|
}
|
|
|
|
const apps: Array<{ name: string; coolifyServiceUuid?: string | null }> =
|
|
projectData.apps ?? [];
|
|
|
|
const targets = appName
|
|
? apps.filter(a => a.name === appName)
|
|
: apps;
|
|
|
|
if (targets.length === 0) {
|
|
return NextResponse.json({ error: `No matching apps found${appName ? ` for "${appName}"` : ''}` }, { status: 404 });
|
|
}
|
|
|
|
const results: Array<{ app: string; deploymentUuid?: string; error?: string }> = [];
|
|
|
|
for (const app of targets) {
|
|
if (!app.coolifyServiceUuid) {
|
|
results.push({ app: app.name, error: 'No Coolify service UUID — app may not be provisioned yet' });
|
|
continue;
|
|
}
|
|
try {
|
|
const deployment = await deployApplication(app.coolifyServiceUuid);
|
|
results.push({ app: app.name, deploymentUuid: deployment.deployment_uuid });
|
|
console.log(`[API] Deploy triggered: ${app.name} → ${deployment.deployment_uuid}`);
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
results.push({ app: app.name, error: msg });
|
|
console.error(`[API] Deploy failed for ${app.name}:`, msg);
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({ results });
|
|
} catch (error) {
|
|
console.error('[POST /api/projects/deploy] Error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to trigger deployment', details: error instanceof Error ? error.message : String(error) },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|