根据我的理解,我们正在注册的服务对象仅由kinvey集合调用。有没有办法在本地进行测试?
我写了下面的代码。
var sdk = require('kinvey-flex-sdk');
const PORT = 8080;
sdk.service({host:'localhost',port:PORT},function(err,flex){
const data = flex.data;
function authentication(request, complete, modules) {
console.log("Inside...");
complete().setBody("Authenticated");
};
const widgets = data.serviceObject('widgets');
widgets.onInsert(authentication);
});
我怀疑是POST请求http://localhost:8080/widgets {} ..
没有触发身份验证功能你可以帮我解决一下吗?
提前致谢..
答案 0 :(得分:0)
您只需运行" node index.js"即可在本地运行该服务。它会启动一个你可以接近的侦听器,例如邮差。每个本地测试都需要一个" POST"到某些路线。测试路线记录在此处:http://devcenter.kinvey.com/ios/guides/flex-services#installation
另见http://devcenter.kinvey.com/guides/flex-services#testing-locally 为了获得必要的标题,您需要在每个请求上设置以获得正确的上下文和权限
答案 1 :(得分:0)
您需要传递以下标题:
Content-Type:application/json
Authorization:Basic <basicAuth>
X-Kinvey-App-Metadata:{ "_id" : "<kinveyAppId>", "appsecret" : "<kinveyAppSecret>", "mastersecret" : "<kinveyMasterSecret>", "baasUrl" : "<kinveyBaseURL>" }
X-Kinvey-Original-Request-Headers:{ "x-kinvey-api-version" : "<KinveyApiVersion>", "authorization" : "Basic <basicAuth>", "x-kinvey-client-app-version" : "<KinveyClientAppVersion>"}
X-Kinvey-Username:<username>
X-Kinvey-User-Id:<userid>
如果你正在使用flex功能:
http://localhost:<port>/_flexFunctions/<flexFunctionName>