Commit Graph

3 Commits

Author SHA1 Message Date
274f5b3b53 fix: Configure Vite proxy to eliminate CORS issues in development
Implemented a comprehensive CORS proxy solution that works with both
local and remote backends during development.

## Changes

### Vite Configuration (vite.config.ts)
- Use loadEnv() to properly read VITE_API_BASE_URL from .env
- Configure proxy to forward /api/* requests to backend
- Add detailed logging for proxy requests and responses
- Support changeOrigin, rewrite, secure=false, and websockets

### API Client (src/lib/api/client.ts)
- In development: Always use /api prefix (proxied)
- In production: Use direct VITE_API_BASE_URL
- Add console logging to show proxy configuration in dev mode
- Automatic detection of environment (DEV vs PROD)

### Error Handling (route loaders)
- Fix console.error() calls that caused TypeError with circular refs
- Use error.message instead of logging full error objects
- Affects: +page.ts, matches/+page.ts

### Documentation
- docs/LOCAL_DEVELOPMENT.md: Complete rewrite with proxy explanation
  - Quick start guide for both production API and local backend
  - Detailed proxy flow diagrams
  - Comprehensive troubleshooting section
  - Clear examples and logs

- docs/CORS_PROXY.md: Technical deep-dive on proxy implementation
  - How the proxy works internally
  - Configuration options explained
  - Testing procedures
  - Common issues and solutions

- .env.example: Updated with proxy documentation

## How It Works

Development Flow:
1. Frontend makes request: /api/matches
2. Vite proxy intercepts and forwards to: ${VITE_API_BASE_URL}/matches
3. Backend responds (no CORS headers needed)
4. Proxy returns response to frontend (same-origin)

Production Flow:
1. Frontend makes request directly to: https://api.csgow.tf/matches
2. Backend responds with CORS headers
3. Browser allows request (CORS enabled on backend)

## Benefits
 No CORS errors in development
 Works with local backend (localhost:8000)
 Works with remote backend (api.csgow.tf)
 Simple configuration (just set VITE_API_BASE_URL)
 Detailed logging for debugging
 Production build unaffected (direct requests)

## Testing
Verified with production API:
- curl https://api.csgow.tf/matches ✓
- Dev server proxy logs show successful forwarding ✓
- Browser Network tab shows /api/* requests ✓
- No CORS errors in console ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 21:34:26 +01:00
d811efc394 feat: complete Phase 3 - Domain Modeling & Data Layer
Implements comprehensive type system, runtime validation, API client,
and testing infrastructure for CS2.WTF.

TypeScript Interfaces (src/lib/types/):
- Match.ts: Match, MatchPlayer, MatchListItem types
- Player.ts: Player, PlayerMeta, PlayerProfile types
- RoundStats.ts: Round economy and performance data
- Weapon.ts: Weapon statistics with hit groups (HitGroup, WeaponType enums)
- Message.ts: Chat messages with filtering support
- api.ts: API responses, errors, and APIException class
- Complete type safety with strict null checks

Zod Schemas (src/lib/schemas/):
- Runtime validation for all data models
- Schema parsers with safe/unsafe variants
- Special handling for backend typo (looses → losses)
- Share code validation regex
- CS2-specific validations (rank 0-30000, MR12 rounds)

API Client (src/lib/api/):
- client.ts: Axios-based HTTP client with error handling
  - Request cancellation support (AbortController)
  - Automatic retry logic for transient failures
  - Timeout handling (10s default)
  - Typed APIException errors
- players.ts: Player endpoints (profile, meta, track/untrack, search)
- matches.ts: Match endpoints (parse, details, weapons, rounds, chat, search)
- Zod validation on all API responses

MSW Mock Handlers (src/mocks/):
- fixtures.ts: Comprehensive mock data for testing
- handlers/players.ts: Mock player API endpoints
- handlers/matches.ts: Mock match API endpoints
- browser.ts: Browser MSW worker for development
- server.ts: Node MSW server for Vitest tests
- Realistic responses with delays and pagination
- Safe integer IDs to avoid precision loss

Configuration:
- .env.example: Complete environment variable documentation
- src/vite-env.d.ts: Vite environment type definitions
- All strict TypeScript checks passing (0 errors, 0 warnings)

Features:
- Cancellable requests for search (prevent race conditions)
- Data normalization (backend typo handling)
- Comprehensive error types (NetworkError, Timeout, etc.)
- Share code parsing and validation
- Pagination support for players and matches
- Mock data for offline development and testing

Build Status: ✓ Production build successful
Type Check: ✓ 0 errors, 0 warnings
Lint: ✓ All checks passed
Phase 3 Completion: 100%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 20:31:20 +01:00
288438a953 feat: complete Phase 1 - Technical Foundations for CS2.WTF rewrite
Initialize SvelteKit project with complete modern web development stack:

## Core Framework
- SvelteKit 2.0 with Svelte 5 and TypeScript strict mode
- Vite 5 for blazing fast dev server and builds
- Node.js 20 standardized via .nvmrc

## Styling & Theming
- Tailwind CSS 3.4 with utility-first approach
- DaisyUI 4.0 with custom CS2 themes (cs2dark/cs2light)
- CS2-branded color palette (T-side orange, CT-side blue)
- PostCSS for CSS processing

## Code Quality & Tooling
- ESLint 8 with TypeScript + Svelte plugins
- Prettier 3 with Svelte + Tailwind plugins
- Stylelint 16 for CSS linting
- Husky 9 + lint-staged for pre-commit hooks
- TypeScript 5.3 with all strict flags enabled

## Testing Infrastructure
- Vitest 1.0 for unit/component tests with jsdom
- Playwright 1.40 for E2E tests (3 browsers)
- Testing Library for component testing
- MSW 2.0 for API mocking
- Coverage thresholds set to 80%

## Project Structure
- Organized src/ with lib/, routes/, mocks/, tests/
- Component directories: layout, ui, charts, match, player
- Path aliases configured: $lib, $components, $stores, $types, $api
- Separate test directories: unit, integration, e2e

## CI/CD & Deployment
- Updated Woodpecker CI pipeline with quality gates
- Pipeline steps: install → lint → type-check → test → build
- Deploy targets: master (prod), dev (staging), cs2-port (preview)

## Documentation
- Comprehensive README.md with setup guide
- API.md with complete backend documentation (12 endpoints)
- TODO.md updated with Phase 0 & 1 completion
- Environment variables template (.env.example)

## Development Experience
- Hot module reloading configured
- Dev server running on port 5173
- All npm scripts defined for dev, test, build workflows
- Pre-commit hooks prevent broken code commits

Project is now ready for feature development (Phase 2+).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 19:54:35 +01:00