'use strict';
const express = require('express');
const app = express();
var request = require('superagent');
var list_profs_ues = [
{
"id_prof": 0,
"id_ue": 2
},
{
"id_prof": 1,
"id_ue": 4
},
{
"id_prof": 3,
"id_ue": 0
},
{
"id_prof": 4,
"id_ue": 1
},
{
"id_prof": 2,
"id_ue": 3
}
];
app.get('/service/:name_prof', (req, callback) => {
request.get(`http://localhost:5020/service/${req.params.name_prof}`, function(err, res){
var result_prof_id = res.body.text;
console.log(result_prof_id);
var result_ue_id;
for (var i = 0; i < list_profs_ues.length; i++){
if (list_profs_ues[i]["id_prof"] == result_prof_id){
console.log(list_profs_ues[i]["id_ue"]);
result_ue_id = list_profs_ues[i]["id_ue"];
}}
request.get(`http://localhost:5030/service/${result_ue_id}`, function(err, res){
if(err || res.body.text == ""){
return callback("some result");
}else{
return callback("some result");
}
});
});
});
module.exports = app;
const server = app.listen(process.env.PORT || 5040, () => {
console.log('Express server listening on port %d in %s mode',
server.address().port, app.settings.env);
});
这显示错误说:回调不是一个功能.... 我的问题很简单,如何才能归还“一些结果”? 我试过了:返回“一些结果”;
任何建议都不仅仅是适用的!
答案 0 :(得分:0)
app.get
中的中间件函数的第二个参数不是回调,而是响应对象。回调是第三个参数:
app.get('/service/:name_prof', (req, res, next) => { ...