Preview
When the user invokes /preview, start the Next.js dev server so they can preview the site locally.
Steps
- •Check if a Next.js dev server is already running by checking for processes listening on port 3000 (
lsof -i :3000) - •If a server is already running:
- •Verify it's healthy by curling
http://localhost:3000 - •If healthy, tell the user the server is already running and they can preview at http://localhost:3000
- •If not healthy, kill the process and continue to step 3
- •Verify it's healthy by curling
- •Check for corrupted
.nextcache that could cause issues:- •If
.nextdirectory exists and seems corrupted (e.g., previous server crashed), remove it withrm -rf .next
- •If
- •Start the dev server with
npm run devin the background - •Wait a few seconds, then verify the server started successfully by curling
http://localhost:3000 - •Tell the user they can preview the site at http://localhost:3000
Rules
- •The dev server runs on port 3000 by default
- •If port 3000 is occupied by a non-Next process, inform the user and suggest they free the port
- •Always run the dev server in the background so the conversation can continue
- •If
npm run devfails, try cleaning.nextandnode_modules/.cachethen retry once - •Always end by telling the user the preview URL: http://localhost:3000