[英]how to authenticate angular post call from nodejs based on stdout and stderr
I am using angular-fullstack generator to create web app. 我正在使用angular-fullstack生成器来创建Web应用程序。 Front end designed using angularjs and server side using nodejs.
前端使用angularjs设计,服务器端使用nodejs。 I have written a python function to know if a host is a linux host or not, which is invoked through nodejs and writes to a file 'This is a valid host' in case of valid linux host.
我写了一个python函数来知道主机是否是linux主机,如果有效的linux主机是通过nodejs调用的,并写入文件'This is a valid host'。 If the host is linux host I want to redirect to different page.
如果主机是linux主机,我想重定向到其他页面。 My angular code:
我的角度代码:
$scope.sendlogin = function () {
console.log("inside click");
var posting = $http({
method: 'POST',
url: '/login',
data: $scope.data,
processData: false
})
posting.success(function (response) {
$location.path("/vprobe");
});
}
My node code: 我的节点代码:
app.post('/login', function (req, res) {
/* Handling the AngularJS post request and storing in a file*/
var fs = require("fs");
console.log(req.body);
var jsonfile = require('jsonfile')
var file = 'login.json'
var obj = req.body;
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
// invoking python child process
var exec = require('child_process').exec;
var arg = 'python checkvalidity.py'
exec(arg, function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
console.log('exec error: ' + error);
res.send(stdout);
});
});
But above code is not working correctly. 但是上面的代码无法正常工作。 For both stdout and stderr its redirecting to page.
对于stdout和stderr,其重定向到页面。 The stdout reads a file which has a content 'This is a valid host'.
标准输出读取内容为“这是有效主机”的文件。 How to redirect only in case of stdout , and display a error in case of a error.
仅在stdout情况下如何重定向,在错误情况下如何显示错误。
也许在您的nodeJs代码if(!stdout)中使用res.sendStatus(500)并使用.error(function(response))将其捕获到您的角度控制器中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.