Node.js 快速/解析-无法获取响应
我已经编写了一些脚本来从解析服务器()获取数据。但是我不能得到结果,我可以请教你一些建议吗。我知道parse.query是一个“承诺函数”,但它应该与简单的get/post请求一起工作Node.js 快速/解析-无法获取响应,node.js,express,parse-platform,Node.js,Express,Parse Platform,我已经编写了一些脚本来从解析服务器()获取数据。但是我不能得到结果,我可以请教你一些建议吗。我知道parse.query是一个“承诺函数”,但它应该与简单的get/post请求一起工作 app.get('/api/getInstant/', function (req, res) { let classname = req.query["cid"]; //cid let colname = req.query["col"]; //col console.log(
app.get('/api/getInstant/', function (req, res) {
let classname = req.query["cid"]; //cid
let colname = req.query["col"]; //col
console.log('OK-1: '+classname+' '+colname+"\n\r");
Parse.initialize(ServerInfo['appId'],ServerInfo['masterKey'],ServerInfo['masterKey'])
Parse.serverURL = ServerInfo['serverURL']
let ReadClass = Parse.Object.extend(classname);
let query = new Parse.Query(ReadClass);
query.exists(colname);
query.descending(DecendingSortBy);
query.limit(1);
console.log('OK-2: Start Query\n\r');
query.find().then((results) => {
// results is an array of parse.object.
_.each(results, function(result) {
let search_result = null
search_result= result.get(colname);
console.log('OK-3: '+search_result+"\n\r");
res.sendStatus(search_result);
})
}).catch((error) => {});
});
这是我在控制台中得到的结果:
示例应用程序正在侦听
更新@180810-1631错误消息
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: 27.2
at ServerResponse.writeHead (_http_server.js:201:11)
at ServerResponse._implicitHeader (_http_server.js:192:8)
at write_ (_http_outgoing.js:637:9)
at ServerResponse.end (_http_outgoing.js:760:5)
at ServerResponse.send (/home/ubuntu/MyComputer-Server/DashboardWeb/node_modules/express/lib/response.js:221:10)
at ServerResponse.sendStatus (/home/ubuntu/MyComputer-Server/DashboardWeb/node_modules/express/lib/response.js:359:15)
at /home/ubuntu/MyComputer-Server/DashboardWeb/WebServerLauncher.js:50:7
at Function._.each._.forEach (/home/ubuntu/MyComputer-Server/DashboardWeb/node_modules/underscore/underscore.js:186:9)
at query.find.then (/home/ubuntu/MyComputer-Server/DashboardWeb/WebServerLauncher.js:46:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
RangeError[ERR\u HTTP\u INVALID\u STATUS\u code]:无效状态代码:27.2
在ServerResponse.writeHead(_http_server.js:201:11)
在ServerResponse._implicitHeader(_http_server.js:192:8)
在写入时(_http_outgoing.js:637:9)
在ServerResponse.end(_http_outgoing.js:760:5)
在ServerResponse.send(/home/ubuntu/mycomputerserver/DashboardWeb/node_modules/express/lib/response.js:221:10)
在ServerResponse.sendStatus(/home/ubuntu/MyComputer Server/DashboardWeb/node_modules/express/lib/response.js:359:15)
在/home/ubuntu/mycomputerserver/DashboardWeb/WebServerLauncher.js:50:7
在Function.each.forEach(/home/ubuntu/MyComputer Server/DashboardWeb/node\u modules/下划线/下划线.js:186:9)
在query.find.then(/home/ubuntu/mycomputerserver/DashboardWeb/WebServerLauncher.js:46:7)
在
在进程中。_tick回调(internal/process/next_tick.js:182:7)
您的代码是正确的,唯一的问题是您试图发送一个无效的
由于这是一个成功的案例,您可以发送200作为状态代码,相应的数据可能会进入响应的req主体
app.get('/api/getInstant/', function (req, res) {
let classname = req.query["cid"]; //cid
let colname = req.query["col"]; //col
console.log('OK-1: '+classname+' '+colname+"\n\r");
Parse.initialize(ServerInfo['appId'],ServerInfo['masterKey'],ServerInfo['masterKey'])
Parse.serverURL = ServerInfo['serverURL']
let ReadClass = Parse.Object.extend(classname);
let query = new Parse.Query(ReadClass);
query.exists(colname);
query.descending(DecendingSortBy);
query.limit(1);
console.log('OK-2: Start Query\n\r');
query.find().then((results) => {
// results is an array of parse.object.
_.each(results, function(result) {
let search_result = null
search_result= result.get(colname);
console.log('OK-3: '+search_result+"\n\r");
res.status(200).json({data: search_result});
})
}).catch((error) => {res.status(500).json({msg: 'Sorry, something went wrong!'})});
});
.catch((错误)=>{console.log(错误)})代码>并查看是否有任何msg27.2不是有效的状态代码…明白了,愚蠢的我,为我愚蠢的问题感到抱歉lol,有时间给予接受一次。
app.get('/api/getInstant/', function (req, res) {
let classname = req.query["cid"]; //cid
let colname = req.query["col"]; //col
console.log('OK-1: '+classname+' '+colname+"\n\r");
Parse.initialize(ServerInfo['appId'],ServerInfo['masterKey'],ServerInfo['masterKey'])
Parse.serverURL = ServerInfo['serverURL']
let ReadClass = Parse.Object.extend(classname);
let query = new Parse.Query(ReadClass);
query.exists(colname);
query.descending(DecendingSortBy);
query.limit(1);
console.log('OK-2: Start Query\n\r');
query.find().then((results) => {
// results is an array of parse.object.
_.each(results, function(result) {
let search_result = null
search_result= result.get(colname);
console.log('OK-3: '+search_result+"\n\r");
res.status(200).json({data: search_result});
})
}).catch((error) => {res.status(500).json({msg: 'Sorry, something went wrong!'})});
});