fix(preview): resolve SQL column error on dev server force-start

This commit is contained in:
2026-06-12 11:31:15 -07:00
parent 576446e36a
commit 2e66ea087b

View File

@@ -14,7 +14,7 @@
import { NextResponse } from "next/server";
import { authSession } from "@/lib/auth/session-server";
import { queryOne } from "@/lib/db-postgres";
import { query, queryOne } from "@/lib/db-postgres";
import { getWorkspaceById } from "@/lib/workspaces";
import {
ensureDevContainer,
@@ -34,14 +34,12 @@ export async function POST(
}
// Load project — verify ownership
const project = await queryOne<{
const projectRows = await query<{
id: string;
slug: string;
name: string;
vibn_workspace_id: string | null;
data: Record<string, unknown>;
}>(
`SELECT p.id, p.slug, p.name, p.vibn_workspace_id, p.data
`SELECT p.id, p.vibn_workspace_id, p.data
FROM fs_projects p
JOIN fs_users u ON u.id = p.user_id
WHERE p.id = $1 AND u.data->>'email' = $2
@@ -49,10 +47,14 @@ export async function POST(
[projectId, session.user.email],
);
if (!project) {
if (projectRows.length === 0) {
return NextResponse.json({ error: "Project not found" }, { status: 404 });
}
const project = projectRows[0];
const projectSlug = (project.data?.slug as string) || project.id;
const projectName = (project.data?.name as string) || "Project";
// 1. Is a dev server already running or starting on the primary port?
const running = await queryOne<{
id: string;
@@ -117,7 +119,7 @@ export async function POST(
// If forceStart is true but we have no history, default to Next.js start command.
const restartOpts = {
projectId: project.id,
projectSlug: project.slug,
projectSlug,
command: last?.command || "next dev -H 0.0.0.0 --no-turbopack",
port: last?.port || 3000,
workspace,
@@ -127,8 +129,8 @@ export async function POST(
try {
await ensureDevContainer({
projectId: project.id,
projectSlug: project.slug,
projectName: project.name,
projectSlug,
projectName,
workspace,
});
const row = await startDevServer(restartOpts);