簡體   English   中英

如何基於stdout和stderr對來自nodejs的角度post調用進行身份驗證

[英]how to authenticate angular post call from nodejs based on stdout and stderr

我正在使用angular-fullstack生成器來創建Web應用程序。 前端使用angularjs設計,服務器端使用nodejs。 我寫了一個python函數來知道主機是否是linux主機,如果有效的linux主機是通過nodejs調用的,並寫入文件'This is a valid host'。 如果主機是linux主機,我想重定向到其他頁面。 我的角度代碼:

$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");
            });

             }

我的節點代碼:

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);
 });

 });

但是上面的代碼無法正常工作。 對於stdout和stderr,其重定向到頁面。 標准輸出讀取內容為“這是有效主機”的文件。 僅在stdout情況下如何重定向,在錯誤情況下如何顯示錯誤。

也許在您的nodeJs代碼if(!stdout)中使用res.sendStatus(500)並使用.error(function(response))將其捕獲到您的角度控制器中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM