feat: update frontend paths to include trailing slashes for consistency

This commit is contained in:
EmanueleAlfano
2026-02-04 14:33:09 +01:00
parent 458b074f45
commit 145a091dc3
6 changed files with 67 additions and 11 deletions

View File

@@ -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 <DebugScreen onBack={() => 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: {
---
### 4Come Cambiare il Path delle API (Opzionale)
### 4Frontend - `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):