mirror of
https://github.com/handsomezhuzhu/AeroStart.git
synced 2026-02-20 20:10:15 +00:00
🐛 fix(api): add Vercel serverless function for Bilibili search suggestions
- Create api/bilibili.ts to handle Bilibili API requests in production - Proxy requests to https://s.search.bilibili.com/main/suggest - Add proper headers (User-Agent, Referer) to avoid blocking - Set CORS headers and cache control (60s) - Handle errors gracefully with fallback response - Update src/utils/suggestions.ts to detect environment - Use /bilibili (Vite proxy) in development - Use /api/bilibili (Vercel Function) in production - Check import.meta.env.DEV to determine environment This fixes the 404 error in production where Vite proxy is not available. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,13 @@ export const fetchSuggestions = (engine: string, query: string): Promise<string[
|
||||
return;
|
||||
}
|
||||
|
||||
// Bilibili uses fetch (via Vite proxy)
|
||||
// Bilibili uses fetch (via Vite proxy in dev, Vercel Function in production)
|
||||
if (engine === 'Bilibili') {
|
||||
const url = `/bilibili?term=${encodeURIComponent(query)}`;
|
||||
// In production (Vercel), use /api/bilibili; in development, use /bilibili (Vite proxy)
|
||||
const isDev = import.meta.env.DEV;
|
||||
const url = isDev
|
||||
? `/bilibili?term=${encodeURIComponent(query)}`
|
||||
: `/api/bilibili?term=${encodeURIComponent(query)}`;
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
|
||||
Reference in New Issue
Block a user