AngularサービスメソッドからOrientDBを照会しようとしています。しかし、認証関連のエラーを取得しています。 私の理解によれば、OrientDBを正常に照会するには2つのGET要求が必要です。AngularアプリケーションでOrientDB HTTP APIを使用するにはどうすればよいですか?
- 認証呼び出し。すなわち、認証ヘッダ
http://localhost:2480/connect/<dbname>
へのリクエスト - 実際のクエリ。すなわち
http://localhost:2480/query/<dbname>/sql/<query_text>
へのお願いしかし、私は、ブラウザのコンソールでこれらのエラーを取得しています:
- のXMLHttpRequestがhttp://localhost:2480/connect/atudbをロードすることはできません。プリフライト要求への応答がアクセス制御チェックに合格しません:要求されたリソースに「Access-Control-Allow-Origin」ヘッダーがありません。発信元 'http://localhost:8080'はアクセスできません。
- はhttp://localhost:2480/query/atudb/sql/select%[email protected]%20as%20rid,%20runOfDay%20from%20TestResult%20where%20executorPlatformData.machineName= 'niteshk' をロードすることはできませんhttp://localhost:2480/query/atudb/sql/select%[email protected]%20as%20rid,%20runOfDay%20from%20TestResult%20where%20executorPlatformData.machineName= 'niteshk' 401(無許可)
- のXMLHttpRequestをGET。要求されたリソースに「Access-Control-Allow-Origin」ヘッダーが存在しません。 Origin 'http://localhost:8080'はアクセスできません。 応答は、HTTPステータスコードの下に401
を持っていた角度のサービスのためのコード
angular.module('ReportApp')
.factory('orientdbService', ['$http', '$log', '$q',
function($http, $log, $q) {
'use strict';
var fac = {};
fac.config = appConfig;
fac.query = function(sql, callback) {
$log.log('Query: '+ sql);
var url=encodeURI(this.config.orientBaseUrl+"query/"+this.config.dbName+"/sql/"+sql);
$log.log('Request URI: '+ url);
connectOrientDb()
.then($http.get(url)
.then(function(response){ //Success
callback(response.data);
},
function(response){ //Failure
callback({
responseStatus: response.status,
responseData: response.data
});
}));
}
fac.fetchCurrentDayReportIdList = function(hostMachineName){
if(typeof(hostMachineName) === "undefined"){
throw {
name: "Parameter Missing",
level: "Show Stopper",
message: "Error detected. This function prameter 'hostMachineName' is mandatory to evaluate return value.",
htmlMessage: "Error detected. This function prameter '<code>hostMachineName</code>' is mandatory to evaluate return value.",
toString: function(){return this.name + ": " + this.message;}
};
}
var sql = "select @rid as rid, runOfDay from TestResult where executorPlatformData.machineName='"+hostMachineName+"'";
var defer = $q.defer()
this.query(sql,
function(data){
defer.resolve(data);
});
return defer.promise;
}
var connectOrientDb = function(){
var url=encodeURI(appConfig.orientBaseUrl+"connect/"+appConfig.dbName);
var req ={
method: 'GET',
url: url,
headers: {
'Authorization': appConfig.authPayload
}
};
$log.log('Request: '+req);
var defer = $q.defer();
$http(req).then(
function(res){ //Success
$log.log('Response: '+res);
defer.resolve(res);
},
function(res){ //Failure
/*throw {
name: "Connection Failed",
level: "Show Stopper",
message: "Error detected ("+response.status+"). Unable to connect to configured database.",
htmlMessage: "Error detected ("+response.status+"). Unable to connect to configured database.",
toString: function(){return this.name + ": " + this.message;}
};*/
defer.reject(res);
}
);
return defer.promise;
}
return fac;
}
]);
fetchCurrentDayReportIdList()
が呼び出されたときに、私はエラーを取得しています。 参考実装を教えてもらえますか、コードで何が間違っているのかを教えてください。
注:
グローバル変数
appConfig
はフォーマット以下のJSONオブジェクトを保持しています。もちろん、@ wolf4oodなどのCORSを有効
{
"orientBaseUrl": "http://localhost:2480/",
"dbName": "atudb",
"dbUser": "root",
"authPayload": "cm9vdDphZG1pbg==",
"dbPassword": "admin",
"formatDateTime": "yyyy-MM-dd HH:mm:ss"
}
こんにちはCORSを有効にする必要があります。http://stackoverflow.com/questions/27612752/building-web-app-using-orientdb-javascript-api – wolf4ood