feat: update frontend paths to include trailing slashes for consistency
This commit is contained in:
@@ -36,6 +36,7 @@ Se in futuro vuoi servire il frontend su un path diverso (es. `/votazioni`, `/ap
|
|||||||
```python
|
```python
|
||||||
# Serve index.html su /badge e sue sub-route
|
# Serve index.html su /badge e sue sub-route
|
||||||
@app.get("/badge")
|
@app.get("/badge")
|
||||||
|
@app.get("/badge/") # Con trailing slash per Playwright e redirect browser
|
||||||
async def serve_badge_index():
|
async def serve_badge_index():
|
||||||
return FileResponse(STATIC_DIR / "index.html")
|
return FileResponse(STATIC_DIR / "index.html")
|
||||||
|
|
||||||
@@ -54,9 +55,14 @@ async def serve_static(filename: str):
|
|||||||
|
|
||||||
**Modifica necessaria:**
|
**Modifica necessaria:**
|
||||||
- Sostituisci `/badge` con il nuovo path desiderato in TUTTE le occorrenze
|
- 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`:
|
- Esempio per `/votazioni`:
|
||||||
```python
|
```python
|
||||||
@app.get("/votazioni")
|
@app.get("/votazioni")
|
||||||
|
@app.get("/votazioni/") # Con trailing slash
|
||||||
|
async def serve_index():
|
||||||
|
return FileResponse(STATIC_DIR / "index.html")
|
||||||
|
|
||||||
@app.get("/votazioni/debug")
|
@app.get("/votazioni/debug")
|
||||||
app.mount("/votazioni/assets", ...)
|
app.mount("/votazioni/assets", ...)
|
||||||
@app.get("/votazioni/{filename:path}")
|
@app.get("/votazioni/{filename:path}")
|
||||||
@@ -106,7 +112,19 @@ return <DebugScreen onBack={() => window.location.href = '/NUOVO_PATH'}/>
|
|||||||
|
|
||||||
**File**: `/frontend/vite.config.ts`
|
**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
|
```typescript
|
||||||
// Proxy API in sviluppo verso il backend (porta 8000)
|
// 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!
|
⚠️ **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`):
|
### Per Cambiare il Path del Frontend (es. `/badge` → `/votazioni`):
|
||||||
|
|
||||||
- [ ] **Backend**: Modifica tutte le route `@app.get("/badge...")` → `@app.get("/NUOVO_PATH...")`
|
- [ ] **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**: Modifica `app.mount("/badge/assets", ...)` → `app.mount("/NUOVO_PATH/assets", ...)`
|
||||||
- [ ] **Backend**: Aggiorna il messaggio di avvio con il nuovo URL
|
- [ ] **Backend**: Aggiorna il messaggio di avvio con il nuovo URL
|
||||||
- [ ] **Frontend**: Aggiorna `basename="/badge"` in `main.tsx`
|
- [ ] **Frontend**: Aggiorna `basename="/badge"` in `main.tsx`
|
||||||
- [ ] **Frontend**: Aggiorna il link di ritorno in `DebugWrapper`
|
- [ ] **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`
|
- [ ] **Frontend**: (Opzionale) Aggiorna i commenti in `vite.config.ts`
|
||||||
- [ ] **Test**: Rebuild del frontend con `./dev.sh build`
|
- [ ] **Test**: Rebuild del frontend con `./dev.sh build`
|
||||||
- [ ] **Test**: Avvio del server con `./dev.sh server`
|
- [ ] **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` 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 `http://localhost:8000/NUOVO_PATH/debug` funzioni
|
||||||
- [ ] **Test**: Verifica che le API continuino a funzionare (servite su `/api/*`)
|
- [ ] **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/*`):
|
### 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 |
|
| `backend-mock/main.py` | Messaggio avvio `print(...)` | ~177 |
|
||||||
| `frontend/src/main.tsx` | `basename="/badge"` in BrowserRouter | ~12 |
|
| `frontend/src/main.tsx` | `basename="/badge"` in BrowserRouter | ~12 |
|
||||||
| `frontend/src/main.tsx` | `window.location.href = '/badge'` | ~8 |
|
| `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/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):
|
### Cambio Path API (`/api/*` → altro):
|
||||||
|
|
||||||
|
|||||||
@@ -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 debug** | `/badge/debug` | Backend (serve static) | `backend-mock/main.py` |
|
||||||
| **Frontend assets** | `/badge/assets/*` | Backend (StaticFiles) | `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 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 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 login** | `/api/login-validate` | Backend API | `backend-mock/api/routes.py` |
|
||||||
| **API anagrafica** | `/api/anagrafica/{badge}` | 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` |
|
| **API ingresso** | `/api/entry-request` | Backend API | `backend-mock/api/routes.py` |
|
||||||
| **Proxy dev** | `/api` → `:8000` | Vite | `frontend/vite.config.ts` |
|
| **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` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ def create_app(data: dict, serve_frontend: bool = True) -> FastAPI:
|
|||||||
|
|
||||||
# Serve index.html su /badge e sue sub-route
|
# Serve index.html su /badge e sue sub-route
|
||||||
@app.get("/badge")
|
@app.get("/badge")
|
||||||
|
@app.get("/badge/") # Con trailing slash per Playwright
|
||||||
async def serve_badge_index():
|
async def serve_badge_index():
|
||||||
return FileResponse(STATIC_DIR / "index.html")
|
return FileResponse(STATIC_DIR / "index.html")
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ async function waitForAppReady(page: Page) {
|
|||||||
|
|
||||||
// Utility per fare login completo come validatore
|
// Utility per fare login completo come validatore
|
||||||
async function loginAsValidator(page: Page, validatorBadge: string = '0008988288') {
|
async function loginAsValidator(page: Page, validatorBadge: string = '0008988288') {
|
||||||
await page.goto('/');
|
await page.goto('/badge/');
|
||||||
await waitForAppReady(page);
|
await waitForAppReady(page);
|
||||||
|
|
||||||
// Passo 1: Passa il badge
|
// Passo 1: Passa il badge
|
||||||
@@ -69,7 +69,7 @@ async function loginAsValidator(page: Page, validatorBadge: string = '0008988288
|
|||||||
test.describe('Flusso Validatore', () => {
|
test.describe('Flusso Validatore', () => {
|
||||||
|
|
||||||
test('01 - mostra schermata attesa badge validatore', async ({ page }) => {
|
test('01 - mostra schermata attesa badge validatore', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/badge/');
|
||||||
await waitForAppReady(page);
|
await waitForAppReady(page);
|
||||||
|
|
||||||
await expect(page.getByText(/passa.*badge/i)).toBeVisible();
|
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 }) => {
|
test('02 - scansione badge mostra campo password', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/badge/');
|
||||||
await waitForAppReady(page);
|
await waitForAppReady(page);
|
||||||
|
|
||||||
// Scansiona un badge
|
// Scansiona un badge
|
||||||
@@ -106,7 +106,7 @@ test.describe('Flusso Validatore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('04 - password errata mostra errore', async ({ page }) => {
|
test('04 - password errata mostra errore', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/badge/');
|
||||||
await waitForAppReady(page);
|
await waitForAppReady(page);
|
||||||
|
|
||||||
// Scansiona badge
|
// Scansiona badge
|
||||||
@@ -126,7 +126,7 @@ test.describe('Flusso Validatore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('05 - pulsante annulla torna a attesa badge', async ({ page }) => {
|
test('05 - pulsante annulla torna a attesa badge', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/badge/');
|
||||||
await waitForAppReady(page);
|
await waitForAppReady(page);
|
||||||
|
|
||||||
// Scansiona badge
|
// Scansiona badge
|
||||||
@@ -257,7 +257,7 @@ test.describe('Conferma Ingresso', () => {
|
|||||||
test.describe('Debug Page', () => {
|
test.describe('Debug Page', () => {
|
||||||
|
|
||||||
test('11 - pagina debug accessibile', async ({ 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();
|
await expect(page.getByRole('heading', { name: 'Debug RFID' })).toBeVisible();
|
||||||
console.log('[E2E] ✓ Pagina debug accessibile');
|
console.log('[E2E] ✓ Pagina debug accessibile');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export default defineConfig({
|
|||||||
|
|
||||||
use: {
|
use: {
|
||||||
// URL base del server (frontend servito su /badge)
|
// URL base del server (frontend servito su /badge)
|
||||||
baseURL: 'http://localhost:8000/badge',
|
baseURL: 'http://localhost:8000/',
|
||||||
|
|
||||||
// Rallenta le azioni per vedere cosa succede
|
// Rallenta le azioni per vedere cosa succede
|
||||||
launchOptions: {
|
launchOptions: {
|
||||||
@@ -55,7 +55,7 @@ export default defineConfig({
|
|||||||
// Server da avviare prima dei test
|
// Server da avviare prima dei test
|
||||||
webServer: {
|
webServer: {
|
||||||
command: 'cd .. && ./dev.sh server -d backend-mock/data/users_test.json',
|
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,
|
reuseExistingServer: !process.env.CI,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export default defineConfig({
|
|||||||
plugins: [react(), tailwindcss()],
|
plugins: [react(), tailwindcss()],
|
||||||
|
|
||||||
// Base path per il frontend servito su /badge
|
// Base path per il frontend servito su /badge
|
||||||
|
// NOTA: trailing slash importante per generare URL corretti degli asset
|
||||||
base: '/badge/',
|
base: '/badge/',
|
||||||
|
|
||||||
// Build nella cartella dist del frontend
|
// Build nella cartella dist del frontend
|
||||||
|
|||||||
Reference in New Issue
Block a user