@@ -339,13 +339,14 @@ export async function loadVocabulary(
339339 }
340340 }
341341
342- // 3. Von URL laden (mit CORS-Proxy für skohub.io)
343- // skohub.io erlaubt keine direkten Browser-Anfragen
344- const fetchUrl = url . includes ( 'skohub.io' )
342+ // 3. Von URL laden (mit CORS-Proxy Fallback)
343+ // Versuche erst direkt, dann mit CORS-Proxy bei Netzwerk-/CORS-Fehler
344+ const needsProxy = url . includes ( 'skohub.io' ) ;
345+ const fetchUrl = needsProxy
345346 ? CORS_PROXY_URL + encodeURIComponent ( url )
346347 : url ;
347348
348- console . log ( `[VocabLoader] Fetching ${ type } from ${ url } ` ) ;
349+ console . log ( `[VocabLoader] Fetching ${ type } from ${ url } ${ needsProxy ? ' (via CORS proxy)' : '' } ` ) ;
349350
350351 try {
351352 const response = await fetch ( fetchUrl , {
@@ -381,6 +382,39 @@ export async function loadVocabulary(
381382 return concepts ;
382383
383384 } catch ( error ) {
385+ // Falls kein Proxy benutzt wurde, mit CORS-Proxy erneut versuchen
386+ if ( ! needsProxy ) {
387+ console . info ( `[VocabLoader] Direct fetch failed for ${ type } , retrying with CORS proxy...` ) ;
388+ try {
389+ const proxyUrl = CORS_PROXY_URL + encodeURIComponent ( url ) ;
390+ const response = await fetch ( proxyUrl , {
391+ headers : {
392+ 'Accept' : 'application/json, application/ld+json'
393+ }
394+ } ) ;
395+
396+ if ( response . ok ) {
397+ const data = await response . json ( ) ;
398+ const concepts = parseSkosJsonLd ( data , url ) ;
399+
400+ if ( concepts . length > 0 ) {
401+ const entry : VocabularyCacheEntry = {
402+ concepts,
403+ fetchedAt : Date . now ( ) ,
404+ url
405+ } ;
406+ memoryCache . set ( type , entry ) ;
407+ saveToLocalStorage ( type , entry ) ;
408+ console . log ( `[VocabLoader] ✅ Loaded ${ concepts . length } concepts for ${ type } (via CORS proxy)` ) ;
409+ return concepts ;
410+ }
411+ }
412+ } catch ( proxyError ) {
413+ // Proxy hat auch nicht funktioniert → Fallback
414+ console . info ( `[VocabLoader] CORS proxy also failed for ${ type } ` ) ;
415+ }
416+ }
417+
384418 // Nur als Info loggen, da Fallback funktioniert
385419 console . info ( `[VocabLoader] Network unavailable for ${ type } , using built-in vocabulary` ) ;
386420 return FALLBACK_VOCABULARIES [ type ] ;
0 commit comments