MarkLogic データベースのデータにアクセスする角度アプリを構築しようとしています。MarkLogic REST API を使用してデータにアクセスしています。アプリを実行しようとすると、次のエラーが表示されます。
XMLHttpRequest はhttp://192.168.192.75:9550/v1/keyvalue?element=fieldId&value=1005&format=jsonを読み込めません 。要求されたリソースに「Access-Control-Allow-Origin」ヘッダーがありません。したがって、オリジン ' http://localhost:8080 ' へのアクセスは許可されていません。
stackoverflow でこの問題に関連する多くの回答を読みましたが、何も機能しませんでした。これが私が今まで試したことです。
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
どちらの方法でも機能しないようです。私が何か間違ったことをしているなら、誰か教えてもらえますか?またはこれを機能させる他の方法がある場合は? 前もって感謝します。