我正在學習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?隨身攜帶是非常漫長和繁瑣的。 –