diff --git a/CHANGE_BASE_PATH.md b/CHANGE_BASE_PATH.md index 99be140..daa3dd7 100644 --- a/CHANGE_BASE_PATH.md +++ b/CHANGE_BASE_PATH.md @@ -36,6 +36,7 @@ Se in futuro vuoi servire il frontend su un path diverso (es. `/votazioni`, `/ap ```python # Serve index.html su /badge e sue sub-route @app.get("/badge") +@app.get("/badge/") # Con trailing slash per Playwright e redirect browser async def serve_badge_index(): return FileResponse(STATIC_DIR / "index.html") @@ -54,9 +55,14 @@ async def serve_static(filename: str): **Modifica necessaria:** - Sostituisci `/badge` con il nuovo path desiderato in TUTTE le occorrenze +- ⚠️ **Importante**: FastAPI richiede ENTRAMBE le route `/path` e `/path/` (con e senza trailing slash) - Esempio per `/votazioni`: ```python @app.get("/votazioni") + @app.get("/votazioni/") # Con trailing slash + async def serve_index(): + return FileResponse(STATIC_DIR / "index.html") + @app.get("/votazioni/debug") app.mount("/votazioni/assets", ...) @app.get("/votazioni/{filename:path}") @@ -106,7 +112,19 @@ return window.location.href = '/NUOVO_PATH'}/> **File**: `/frontend/vite.config.ts` -**Cerca la configurazione proxy** (circa linea 32): +**Cerca il base path per il build** (circa linea 10): + +```typescript +// Base path per il frontend servito su /badge +base: '/badge/', +``` + +**Modifica necessaria:** +- Cambia `base: '/badge/'` con il nuovo path +- Esempio: `base: '/votazioni/'` oppure `base: '/'` per la root +- ⚠️ **Il trailing slash è importante!** + +**Cerca anche la configurazione proxy** (circa linea 32): ```typescript // Proxy API in sviluppo verso il backend (porta 8000) @@ -129,7 +147,33 @@ server: { --- -### 4️⃣ Come Cambiare il Path delle API (Opzionale) +### 4️⃣ Frontend - `frontend/playwright.config.ts` + +**File**: `/frontend/playwright.config.ts` + +**Cerca baseURL** (circa linea 22): + +```typescript +use: { + // URL base del server (frontend servito su /badge) + baseURL: 'http://localhost:8000/badge', +``` + +**Cerca webServer.url** (circa linea 58): + +```typescript +webServer: { + command: 'cd .. && ./dev.sh server -d backend-mock/data/users_test.json', + url: 'http://localhost:8000/badge', +``` + +**Modifica necessaria:** +- Aggiorna entrambi gli URL con il nuovo path +- Esempio: `http://localhost:8000/votazioni` + +--- + +### 5️⃣ Come Cambiare il Path delle API (Opzionale) ⚠️ **Attenzione**: Questo è separato dal path del frontend! @@ -202,16 +246,21 @@ async def serve_static(filename: str): ### Per Cambiare il Path del Frontend (es. `/badge` → `/votazioni`): - [ ] **Backend**: Modifica tutte le route `@app.get("/badge...")` → `@app.get("/NUOVO_PATH...")` +- [ ] **Backend**: ⚠️ Aggiungi route con trailing slash `@app.get("/NUOVO_PATH/")` per Playwright - [ ] **Backend**: Modifica `app.mount("/badge/assets", ...)` → `app.mount("/NUOVO_PATH/assets", ...)` - [ ] **Backend**: Aggiorna il messaggio di avvio con il nuovo URL - [ ] **Frontend**: Aggiorna `basename="/badge"` in `main.tsx` - [ ] **Frontend**: Aggiorna il link di ritorno in `DebugWrapper` +- [ ] **Frontend**: Aggiorna `base: '/badge/'` in `vite.config.ts` +- [ ] **Frontend**: Aggiorna `baseURL` e `webServer.url` in `playwright.config.ts` - [ ] **Frontend**: (Opzionale) Aggiorna i commenti in `vite.config.ts` - [ ] **Test**: Rebuild del frontend con `./dev.sh build` - [ ] **Test**: Avvio del server con `./dev.sh server` - [ ] **Test**: Verifica che `http://localhost:8000/NUOVO_PATH` funzioni +- [ ] **Test**: Verifica che `http://localhost:8000/NUOVO_PATH/` (con slash) funzioni - [ ] **Test**: Verifica che `http://localhost:8000/NUOVO_PATH/debug` funzioni - [ ] **Test**: Verifica che le API continuino a funzionare (servite su `/api/*`) +- [ ] **Test**: Test E2E con `./dev.sh test:e2e` ### Per Cambiare il Path delle API (es. `/api/*` → `/v1/*`): @@ -256,7 +305,10 @@ curl http://localhost:8000/api/anagrafica/0008988288 | `backend-mock/main.py` | Messaggio avvio `print(...)` | ~177 | | `frontend/src/main.tsx` | `basename="/badge"` in BrowserRouter | ~12 | | `frontend/src/main.tsx` | `window.location.href = '/badge'` | ~8 | +| `frontend/vite.config.ts` | `base: '/badge/'` per build | ~10 | | `frontend/vite.config.ts` | Commento documentazione (opzionale) | ~32 | +| `frontend/playwright.config.ts` | `baseURL` in use | ~22 | +| `frontend/playwright.config.ts` | `webServer.url` | ~58 | ### Cambio Path API (`/api/*` → altro): diff --git a/PATH_STRUCTURE.md b/PATH_STRUCTURE.md index 71cf082..f086e5f 100644 --- a/PATH_STRUCTURE.md +++ b/PATH_STRUCTURE.md @@ -134,12 +134,14 @@ Per modificare i path, consulta **`CHANGE_BASE_PATH.md`** che spiega: | **Frontend debug** | `/badge/debug` | Backend (serve static) | `backend-mock/main.py` | | **Frontend assets** | `/badge/assets/*` | Backend (StaticFiles) | `backend-mock/main.py` | | **Frontend router** | `/badge` (basename) | React Router | `frontend/src/main.tsx` | +| **Frontend build** | `/badge/` (base) | Vite | `frontend/vite.config.ts` | | **API info sala** | `/api/info-room` | Backend API | `backend-mock/api/routes.py` | | **API login** | `/api/login-validate` | Backend API | `backend-mock/api/routes.py` | | **API anagrafica** | `/api/anagrafica/{badge}` | Backend API | `backend-mock/api/routes.py` | | **API ingresso** | `/api/entry-request` | Backend API | `backend-mock/api/routes.py` | | **Proxy dev** | `/api` → `:8000` | Vite | `frontend/vite.config.ts` | -| **Test E2E** | `baseURL: /badge` | Playwright | `frontend/playwright.config.ts` | +| **Test E2E baseURL** | `/badge` | Playwright | `frontend/playwright.config.ts` | +| **Test E2E health** | `/badge` (webServer.url) | Playwright | `frontend/playwright.config.ts` | --- diff --git a/backend-mock/main.py b/backend-mock/main.py index 330d283..652dab8 100644 --- a/backend-mock/main.py +++ b/backend-mock/main.py @@ -87,6 +87,7 @@ def create_app(data: dict, serve_frontend: bool = True) -> FastAPI: # Serve index.html su /badge e sue sub-route @app.get("/badge") + @app.get("/badge/") # Con trailing slash per Playwright async def serve_badge_index(): return FileResponse(STATIC_DIR / "index.html") diff --git a/frontend/e2e/app.spec.ts b/frontend/e2e/app.spec.ts index 23389bb..df7906c 100644 --- a/frontend/e2e/app.spec.ts +++ b/frontend/e2e/app.spec.ts @@ -36,7 +36,7 @@ async function waitForAppReady(page: Page) { // Utility per fare login completo come validatore async function loginAsValidator(page: Page, validatorBadge: string = '0008988288') { - await page.goto('/'); + await page.goto('/badge/'); await waitForAppReady(page); // Passo 1: Passa il badge @@ -69,7 +69,7 @@ async function loginAsValidator(page: Page, validatorBadge: string = '0008988288 test.describe('Flusso Validatore', () => { test('01 - mostra schermata attesa badge validatore', async ({ page }) => { - await page.goto('/'); + await page.goto('/badge/'); await waitForAppReady(page); await expect(page.getByText(/passa.*badge/i)).toBeVisible(); @@ -80,7 +80,7 @@ test.describe('Flusso Validatore', () => { }); test('02 - scansione badge mostra campo password', async ({ page }) => { - await page.goto('/'); + await page.goto('/badge/'); await waitForAppReady(page); // Scansiona un badge @@ -106,7 +106,7 @@ test.describe('Flusso Validatore', () => { }); test('04 - password errata mostra errore', async ({ page }) => { - await page.goto('/'); + await page.goto('/badge/'); await waitForAppReady(page); // Scansiona badge @@ -126,7 +126,7 @@ test.describe('Flusso Validatore', () => { }); test('05 - pulsante annulla torna a attesa badge', async ({ page }) => { - await page.goto('/'); + await page.goto('/badge/'); await waitForAppReady(page); // Scansiona badge @@ -257,7 +257,7 @@ test.describe('Conferma Ingresso', () => { test.describe('Debug Page', () => { test('11 - pagina debug accessibile', async ({ page }) => { - await page.goto('/debug'); + await page.goto('/badge/debug'); await expect(page.getByRole('heading', { name: 'Debug RFID' })).toBeVisible(); console.log('[E2E] ✓ Pagina debug accessibile'); diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 5c9cd41..0ed833e 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -20,7 +20,7 @@ export default defineConfig({ use: { // URL base del server (frontend servito su /badge) - baseURL: 'http://localhost:8000/badge', + baseURL: 'http://localhost:8000/', // Rallenta le azioni per vedere cosa succede launchOptions: { @@ -55,7 +55,7 @@ export default defineConfig({ // Server da avviare prima dei test webServer: { command: 'cd .. && ./dev.sh server -d backend-mock/data/users_test.json', - url: 'http://localhost:8000', + url: 'http://localhost:8000/badge/', reuseExistingServer: !process.env.CI, timeout: 30000, }, diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index d0a7e66..47ae706 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -8,6 +8,7 @@ export default defineConfig({ plugins: [react(), tailwindcss()], // Base path per il frontend servito su /badge + // NOTA: trailing slash importante per generare URL corretti degli asset base: '/badge/', // Build nella cartella dist del frontend