2.4 KiB
2.4 KiB
Frontend Replacement: search-zen-50 Integration
Status
Approved
Overview
Replace the current Go template-based frontend (HTMX + Go templates) with the search-zen-50 React SPA. The React app is built statically and embedded into the Go binary, serving as a single binary deployment.
Architecture
- Build: React/Vite app builds to
dist/directory - Embed: Go's
//go:embedembeds the dist folder into the binary - Serve: Go HTTP server serves static files and handles API routes
- SPA routing: Non-API routes serve
index.htmlfor React Router
Changes
Go Side
-
Create
internal/spa/spa.go- Embeds the React build (
dist/) using//go:embed - Serves static files (JS, CSS, images)
- Handles SPA fallback: serves
index.htmlfor all non-API routes - Provides
SPAHandlerthat wraps API routes
- Embeds the React build (
-
Modify
cmd/kafka/main.go- Import the embedded SPA files
- Route
/,/preferences, and unknown routes to SPA handler - Keep existing API routes:
/search,/autocompleter,/healthz,/opensearch.xml
React Side
-
Modify
use-search.ts- Replace mock data with real API call:
fetch("/search?format=json&q=${encodeURIComponent(query)}") - Map response to existing
SearXNGResponsetype (already matches)
- Replace mock data with real API call:
-
Add autocomplete (optional enhancement)
- Call
/autocompleter?q=${encodeURIComponent(query)} - Display suggestions while typing
- Call
-
Keep unchanged
- All UI components
- Preferences page (localStorage-based)
- Routing (React Router)
Data Flow
Browser → GET / → Go serves embedded index.html
Browser → GET /search?format=json&q=... → Go search handler → JSON
Browser → React renders results via use-search hook
API Compatibility
The existing kafka API (/search?format=json) already matches the expected SearXNGResponse interface in the React code:
query: stringnumber_of_results: numberresults: SearchResult[]suggestions: string[]unresponsive_engines: string[][]
File Changes
- New:
internal/spa/spa.go - Modified:
cmd/kafka/main.go(wire SPA handler) - Modified:
src/hooks/use-search.ts(use real API) - Build step:
npm run buildorbun run buildin search-zen-50
Dependencies
- React app uses
@tanstack/react-queryfor API calls (already in package.json) - No new Go dependencies needed