Sto provando a creare un'app angolare per accedere ai dati dal database MarkLogic. Sto usando MarkLogic Rest API per accedere ai dati. Quando provo a eseguire l'app, ottengo il seguente errore.Errore 'Access-Control-Allow-Origin' anche dopo aver seguito 2 approcci
XMLHttpRequest non può caricare http://192.168.192.75:9550/v1/keyvalue?element=fieldId&value=1005&format=json. Nessuna intestazione 'Access-Control-Allow-Origin' è presente sulla risorsa richiesta. L'origine 'http://localhost:8080' non è quindi consentita l'accesso .
Ho letto molte risposte relative a questo problema su StackOverflow ma non ho potuto ottenere nulla di funzionamento. Ecco cosa ho provato fino ad ora.
1) Setting the response header using xdmp in qconsole
xdmp:add-response-header("Access-Control-Allow-Origin", "*");
xdmp:add-response-header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
xdmp:add-response-header("Access-Control-Allow-Headers", "x-requested-with, X-Auth-Token, Content-Type");
2) Tried to add headers by using REST [Extention][1]. Here is the example.sjs file which I wrote.
a) function get(context, params) {
var results = [];
context.outputTypes = [];
for (var pname in params) {
if (params.hasOwnProperty(pname)) {
results.push({name: pname, value: params[pname]});
context.outputTypes.push('application/json');
}
}
context.outputStatus = [201, 'Created My New Resource'];
context.outputHeaders =
{'Access-Control-Allow-Origin' : '*', 'Access-Control-Allow-Methods' : 'GET, OPTIONS, DELETE', 'Access-Control-Allow-Headers' : 'x-requested-with, X-Auth-Token, Content-Type'};
return xdmp.arrayValues(results);
};
exports.GET = get;
b) curl --anyauth --user admin:admin -X PUT -i -H "Content-type: application/vnd.marklogic-javascript" --data-binary @./example.sjs http://192.168.192.75:9550/LATEST/config/resources/example
Non sembra funzionare, in entrambi i modi. Qualcuno può dirmi se sto facendo qualcosa di sbagliato? o Se ci sono altri modi per farlo funzionare? Grazie in anticipo.
@Tang grazie per la risposta. Stavo guardando un approccio a 2 livelli. Ad esempio Angolare con Marklogic che utilizza l'API Rest. Ho trovato un modo alternativo sin d'ora per raggiungere questo obiettivo. Lo posterò ora. – DMA