From 21a11a84b2a486a341906e59ec4baecc2b55d55b Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 9 Nov 2025 16:22:33 +0000 Subject: [PATCH 1/2] Fix: Make npm start command work for both standalone and default Next.js builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Appwrite Sites deployment hangs/times out - server never responds - Build succeeds but site is unreachable at https://app.sfplib.com/ - Current start script hardcoded to: node .next/standalone/server.js - This file only exists when using output: 'standalone' in next.config.ts - When deploying without standalone mode, npm start fails silently Root Cause: - Appwrite Sites expects standard Next.js build (per their docs) - Standard builds require 'next start' command - Our script tries to run non-existent standalone server.js - Result: No server process starts, site times out Solution: Detect which build type was created and use appropriate start command: - If .next/standalone/server.js exists → node .next/standalone/server.js - Otherwise → next start This allows the same package.json to work for multiple deployment modes: - Appwrite Sites (standard Next.js SSR) - Docker/Home Assistant (standalone mode) Testing: - Verified with Playwright: site currently times out (no server running) - After fix: npm start will launch appropriate server - Docker/HA builds remain unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/package.json b/frontend/package.json index 493557b..b53e76a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,7 +12,7 @@ "dev": "next dev --turbopack", "build": "next build --turbopack", "postbuild": "if [ -d .next/standalone ]; then cp -r .next/static .next/standalone/.next/static && if [ -d public ]; then cp -r public .next/standalone/public; fi; fi", - "start": "node .next/standalone/server.js", + "start": "if [ -f .next/standalone/server.js ]; then node .next/standalone/server.js; else next start; fi", "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"", "lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"", "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"", From e7200d0744b8424143c47517207effec9a53ddb3 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 9 Nov 2025 16:51:02 +0000 Subject: [PATCH 2/2] Debug: Add logging to diagnose environment variable detection --- frontend/next.config.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frontend/next.config.ts b/frontend/next.config.ts index 9fe018e..ea22830 100644 --- a/frontend/next.config.ts +++ b/frontend/next.config.ts @@ -25,6 +25,14 @@ const withBundleAnalyzer = initializeBundleAnalyzer({ * Standalone/HA modes use REST API pattern via /api/* rewrites. * Appwrite mode uses native Appwrite SDK (no backend API needed). */ +// Debug: Log environment variables during build +console.log('[next.config.ts] Build-time environment check:'); +console.log(' APPWRITE_SITE_API_ENDPOINT:', process.env.APPWRITE_SITE_API_ENDPOINT || 'NOT SET'); +console.log(' APPWRITE_SITE_PROJECT_ID:', process.env.APPWRITE_SITE_PROJECT_ID || 'NOT SET'); +console.log(' APPWRITE_ENDPOINT:', process.env.APPWRITE_ENDPOINT || 'NOT SET'); +console.log(' APPWRITE_PROJECT_ID:', process.env.APPWRITE_PROJECT_ID || 'NOT SET'); +console.log(' DEPLOYMENT_MODE:', process.env.DEPLOYMENT_MODE || 'NOT SET'); + const isAppwriteSite = !!( process.env.APPWRITE_SITE_API_ENDPOINT || process.env.APPWRITE_SITE_PROJECT_ID || @@ -36,6 +44,9 @@ const isStandalone = deploymentMode === 'standalone'; const isHomeAssistant = deploymentMode === 'homeassistant'; const isAppwrite = deploymentMode === 'appwrite'; +console.log('[next.config.ts] Detected deployment mode:', deploymentMode); +console.log('[next.config.ts] Will use output:', isAppwrite ? 'DEFAULT (no standalone)' : 'standalone'); + // Only standalone and HA modes need the appwrite stub (no direct SDK usage) const require = createRequire(import.meta.url); const standaloneAppwriteAlias = require.resolve('./src/lib/appwrite-standalone');