linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
562 stars 142 forks source link

Whether cross-domain URIs are supported by rdflib.js? #584

Closed chenkuncloud closed 1 year ago

chenkuncloud commented 1 year ago

Hi,

Whether cross-domain URIs are supported by rdflib.js?

The following URIs are not parsed by fetcher.nowOrWhenFetched:

Error:

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Code:

// source:https://github.com/solidos/solid-tutorial-rdflib.js#fetch-data-into-the-store-from-the-web
var uri = 'http://purl.obolibrary.org/obo/GENEPIO_0100155';
var store = $rdf.graph();
var timeout = 5000; // 5000 ms timeout
var fetcher = new $rdf.Fetcher(store, timeout);
fetcher.nowOrWhenFetched(uri, function(ok, body, response) {
    if (!ok) {
        console.log("Oops, something happened and couldn't fetch data " + body);
    } else if (response.onErrorWasCalled || response.status !== 200) {
        console.log('    Non-HTTP error reloading data! onErrorWasCalled=' + response.onErrorWasCalled + ' status: ' + response.status);
    } else {
        console.log("---data loaded---");

        var dataList = store.statements;
        for (var i=0; i<dataList.length;i++) {
            data = dataList[i]
            console.log(data)
        }

        console.log(store.namespaces);
    }
});

Best regards

jeff-zucker commented 1 year ago

The error I get is : Access to fetch at 'https://www.w3.org/2000/01/rdf-schema' from origin 'http://localhost:3101' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Have the server send the header with a valid value ... In other words, it is a problem on the server, not the client.

jeff-zucker commented 1 year ago

Note : the error above was from window.fetch(). Rdflib gives the first part of the error message but doesn't include the advice bout the server.

chenkuncloud commented 1 year ago

Thanks.

As you said, this is not a problem with rdflib.js, it is a problem with the server.

rdflib.js can parse IRI that which server allow CORS.