我正在学习webtask.io,所以我编写了一个简单的REST API(我没有在这里使用Express.js,但也许我应该)。这是一个小的webtask.io应用程序,它连接到一个mlab MongoDB数据库并从任务列表集合中检索待办事项。问题是,我得到这个错误:我的mongoDB api得到一个webtask.io令牌错误
{ “代码”:404, “消息”: “无法解决JTN到webtask令牌”, “REQ_ID”: “1504385487318.83712”}”
?任何想法如何解决这个错误,这里是我的代码片段:
var MongoClient = require('mongodb').MongoClient;
...
module.exports =
function (ctx, req, res) {
// write the header and set the response type as a json
res.writeHead(200, { 'Content-Type': 'application/json' });
MongoClient.connect(ctx.data.MONGO_URL, function (err, db) {
if (err) {
res.writeHead(400, { 'Content-Type': 'application/json'});
res.end(JSON.stringify(ERROR_RESPONSE.CONNECT_ERROR));
} else {
switch(req.method) {
case 'GET':
db.collection('tasklist').find({}).sort({"dateAdded" : -1}).toArray(function(err, docs) {
if (err) {
res.writeHead(400, { 'Content-Type': 'application/json'});
res.end(JSON.stringify(ERROR_RESPONSE.GET_ERROR));
} else {
res.end(JSON.stringify(docs));
}
}); //toArray
break;
//post, delete, and put are in here
} //switch
} //else no error
db.close();
}); //Mongo connect
res.end();
} //export function
几岁是您的令牌? – user10089632
这已经过了几天了,我通过https://webtask.io/token获得了它。你能给我一些关于如何设置它的方向,并指定它在一个URL中,说key = value?随身携带是非常漫长和繁琐的。 –