Add debug logging to BitMidi search + better headers

- Log fetch URL, response status, and HTML size
- Use realistic Chrome User-Agent headers
- Helps diagnose Cloudflare blocking on Vercel

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
b1rdmania
2025-12-29 11:05:22 +00:00
parent 9d38a9a83a
commit 622199e27c
+9 -1
View File
@@ -8,17 +8,25 @@ export class BitMidiAdapter implements SearchAdapter {
async search(query: string): Promise<MIDICandidate[]> {
try {
const searchUrl = `${this.baseUrl}/search?q=${encodeURIComponent(query)}`;
console.log(`BitMidi: Fetching ${searchUrl}`);
const response = await fetch(searchUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MotifBot/1.0)'
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
}
});
console.log(`BitMidi: Response status ${response.status}`);
if (!response.ok) {
throw new Error(`BitMidi search failed: ${response.status}`);
}
const html = await response.text();
console.log(`BitMidi: Got ${html.length} bytes, has initStore: ${html.includes('window.initStore')}`);
return this.parseSearchResults(html, query);
} catch (error) {
console.error('BitMidi search error:', error);