diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b737e3..ea047a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: cache: 'npm' - name: Install dependencies - run: npm ci + run: npm install - name: Run ESLint run: npm run lint --if-present || echo "No lint script found" @@ -47,7 +47,7 @@ jobs: cache: 'npm' - name: Install dependencies - run: npm ci + run: npm install - name: Run unit tests run: npm test --if-present || echo "No test script found" @@ -75,7 +75,7 @@ jobs: cache: 'npm' - name: Install dependencies - run: npm ci + run: npm install - name: Build application run: npm run build @@ -101,7 +101,7 @@ jobs: cache: 'npm' - name: Install dependencies - run: npm ci + run: npm install - name: Install Playwright browsers run: npx playwright install --with-deps chromium diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index f9e8088..49a5f88 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -21,7 +21,7 @@ jobs: cache: 'npm' - name: Install dependencies - run: npm ci + run: npm install - name: Install Playwright Browsers run: npx playwright install --with-deps diff --git a/README.md b/README.md index 7b870dd..ad1fc1e 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,25 @@ npx playwright install npm run dev ``` +### Troubleshooting + +**Getting 502 Bad Gateway errors?** + +The dev server must run on port 5000 for Codespaces forwarding: + +```bash +# Run diagnostics +bash scripts/diagnose-502.sh + +# Kill any existing server +npm run kill + +# Start fresh +npm run dev +``` + +For detailed troubleshooting, see [docs/502_ERROR_FIX.md](./docs/502_ERROR_FIX.md) + ### Quick Start 1. **Save Your Work** - Use **Save Project** button to persist your work to the database 2. **Load Projects** - Click **Load Project** to view and switch between saved projects diff --git a/docs/502_ERROR_FIX.md b/docs/502_ERROR_FIX.md new file mode 100644 index 0000000..1b2c70a --- /dev/null +++ b/docs/502_ERROR_FIX.md @@ -0,0 +1,164 @@ +# 502 Bad Gateway Error Fix Guide + +## Problem Summary + +You're experiencing multiple related issues: + +1. **502 Bad Gateway errors** - Vite dev server not accessible +2. **Port mismatch** - Server configured for port 5173, but Codespaces URL uses port 5000 +3. **CI/CD failures** - workspace dependencies causing `npm ci` to fail +4. **Resource loading errors** - MIME type mismatches due to dev server being unreachable + +## Root Causes + +### 1. Port Mismatch (FIXED) +- **Problem**: Vite was configured to run on port 5173, but your Codespaces forwarded URL expects port 5000 +- **Solution**: Updated `vite.config.ts` to use port 5000 +- **Status**: ✅ FIXED + +### 2. Workspace Dependencies Issue +- **Problem**: `package.json` uses `"@github/spark": "workspace:*"` which `npm ci` doesn't support +- **Impact**: CI/CD pipelines fail with `EUNSUPPORTEDPROTOCOL` error +- **Solutions**: + - **Option A**: Use `npm install` instead of `npm ci` (loses lockfile validation) + - **Option B**: Switch to `pnpm` (better workspace support) + - **Option C**: Remove workspace protocol and use version numbers (breaks local development) + +### 3. Server Not Running +- **Problem**: Dev server may not be started or may have crashed +- **Solution**: Ensure `npm run dev` is running in Codespaces terminal + +## Quick Fix Steps + +### Step 1: Restart the Dev Server +```bash +# Kill any existing processes on port 5000 +npm run kill + +# Start the dev server +npm run dev +``` + +The server should now start on port 5000 and bind to `0.0.0.0` (accessible externally). + +### Step 2: Verify Port Forwarding +1. Open the **Ports** panel in VS Code/Codespaces +2. Verify that port **5000** is listed and forwarded +3. If not listed, the server isn't running - check Step 1 +4. Click the globe icon to open the forwarded URL + +### Step 3: Fix CI/CD (Choose One Option) + +#### Option A: Use `npm install` (Quick Fix) +Update `.github/workflows/ci.yml` to replace all `npm ci` with `npm install`. + +**Pros**: Works immediately with workspace dependencies +**Cons**: Doesn't validate lockfile, potentially slower + +#### Option B: Switch to pnpm (Recommended) +1. Add pnpm setup to workflows: +```yaml +- name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + +- name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'pnpm' + +- name: Install dependencies + run: pnpm install +``` + +2. Update all `npm` commands to `pnpm` +3. Commit `pnpm-lock.yaml` instead of `package-lock.json` + +**Pros**: Native workspace support, faster, more reliable +**Cons**: Requires workflow updates + +#### Option C: Remove Workspace Protocol (Not Recommended) +Change `package.json`: +```json +"@github/spark": "1.0.0" +``` + +**Pros**: Works with `npm ci` +**Cons**: Breaks local monorepo setup, requires manual version syncing + +## Expected Results After Fix + +### Dev Server (Local/Codespaces) +``` + VITE v7.3.1 ready in 1234 ms + + ➜ Local: http://localhost:5000/ + ➜ Network: http://0.0.0.0:5000/ + ➜ press h + enter to show help +``` + +### Browser Console +- No 502 errors +- Vite client loads successfully +- React app renders properly +- HMR (Hot Module Replacement) works + +### CI/CD Pipeline +- `npm install` (or `pnpm install`) succeeds +- Build completes without errors +- Tests run successfully + +## Troubleshooting + +### Still Getting 502 Errors? + +1. **Check if server is running**: + ```bash + lsof -i :5000 + # Should show node/vite process + ``` + +2. **Check server logs**: + - Look for errors in terminal where `npm run dev` is running + - Common issues: port conflicts, missing dependencies, syntax errors + +3. **Verify network binding**: + - Ensure vite.config.ts has `host: '0.0.0.0'` + - Localhost-only binding (`127.0.0.1`) won't work in Codespaces + +4. **Check Codespaces port visibility**: + - In Ports panel, ensure port 5000 is set to "Public" or "Private to Organization" + - "Private" (local only) won't work from browser + +### MIME Type Errors? + +These are usually secondary to 502 errors. Once the dev server is accessible: +- Vite serves files with correct MIME types +- `@vite/client` loads as JavaScript +- `.css` files load as stylesheets +- HMR works properly + +If MIME errors persist after fixing 502s, check: +- `index.html` for incorrect `` or `