我的应用程序在localhost:8080上运行,node express在localhost:8081上运行。
我的任务是当特定网址被点击时说
localhost:8080/autoSearch
这应该被node express中间件读取并在localhost上再发一个请求:8080 / logusercheck如果返回true则再次调用以获得结果。
" localhost:8080 / logusercheck如果用户已登录"
,则返回true实现相同的目标
在服务器上安装xamp并添加条目
ProxyPass "/autoSearch" "http://localhost:8081/autolink" ttl=120 ProxyPassReverse /autoSearch http://localhost:8081/autolink
在节点入口点
var express = require('express');
var app = express();
var port = 8081;
var request = require('request');
app.get('/autolink', function (req, res) {
/*Whether user is logged in or not logged --> localhost:8080*/
request('/logusercheck',function(error, response, body){
console.log(response);
console.log(error);
console.log(body);
if (!error && response.statusCode == 200) {
res.send('Searching');
}else{
res.send('you are not logged in');
}
});
});
app.listen(port,function(err,res){
if(err){
console.log('server error');
}else{
console.log('Express Started');
}
});
console.log('server started');
这总是返回"您尚未登录"
抚慰
reponse undefined
error [Error: Invalid URI "/logusercheck"]
body undefined
我在这里做错了什么。
答案 0 :(得分:1)
request
应该传递完整的网址:
request('http://localhost:8080/logusercheck', ...);