如果有人在Kinvey工作(Mbaas)请使用nodeJS帮助设置数据链接项目
我是nodeJS的新手,我基于kinvey示例创建了一个nodejs项目。
以下是nodejs代码示例
var configTools = require("./config");
var util = require("util");
var querystring = require('querystring');
var ServiceLink = require('./service_link');
var restify = require('restify');
var server = restify.createServer();
//Configure the server to parse the request body into req.body
server.use(restify.bodyParser({ mapParams: false }));
//insert into call chain when debugging
var debug = function(req, res, next) {
if (config.debug){
var method = req.method;
var params = req.params;
var query = req.query;
var body = req.body;
console.log("Method: " + method +
"\nParams: " + util.inspect(params, false, null, true) +
"\nQuery: " + util.inspect(query, false, null, true) +
"\nBody: " + util.inspect(body, false, null, true) + "\n");
}
if (config.debugFullRequest){
console.log(util.inspect(req));
}
return next();
}
// Verify key matches the header
var keyauth = function(req,res,next) {
var key = req.headers['x-auth-key'];
if (key != config.key) {
return next(new restify.InvalidCredentialsError("Invalid API Key"));
} else {
next();
}
}
//Router functions
var extractReq = function(req, next){
if (!req){ return new restify.InternalError("ServiceLink is having problems..."); }
var params = req.params;
var query = req.query;
var body = req.body;
var output = {query: null, params: null, body: null, route: null};
// Extract query
if (query && query !== undefined){
try {
var parsedString = querystring.parse(query);
output["query"] = JSON.parse(parsedString.query);
} catch (e){
return new restify.InvalidContentError("JSON query exception: " + e);
}
}
// Extract route
if (params && params !== undefined){
try {
var s = "";
s = params.collection;
if (params.id){
s = s + "/" + params.id;
}
output["route"] = s;
} catch (e){
return new restify.InvalidContentError("Invalid Params: " + e);
}
}
// Extract body
if (body && body !== undefined){
try {
output["body"] = body;
} catch (e){
return new restify.InvalidContentError("JSON body exception: " + e);
}
}
return output;
};
var preGet = function(req, res, next){
var data = extractReq(req, next);
if (data instanceof Error){
return next(data);
}
ServiceLink.get(data["route"], data["query"], data["body"], res, next);
};
server.get(/\/public\/?.*/, restify.serveStatic({
directory: './docs',
default: 'index.html'
}));
//For debugging we add in the debug middleware
server.get('/:stateList', keyauth, debug, preGet);
server.listen(3000, function() {
console.log('%s listening at %s', server.name, server.url);
});
如果你查看代码,我已经为路由创建了角度前端和供应索引页面。
我的html文件加载正常,因为我将调用kinvey数据存储区,即stateList 像这样
var promise = $kinvey.DataStore.find('stateList');
但是它给了我500个错误,当我使用datalink映射集合时,它给出了错误“_count endpoint to to data in data link connector”
我的数据链接链接是http://localhost:3000/
任何人都请指导我这个映射。 感谢