angular语言 - 双簧管+ NodeJS流错误前非空白字符



NodeJS server:

var exec = require('child_process').exec;
app.get('/ls', function(req, res) {
  exec('ls',
    function (error, stdout, stderr) {
      res.send(stdout);
  });
});

Angular客户端(来自其GitHubPage上的示例的标准实现):

$scope.myData = [];

Oboe({
        url: $scope.baseUrl + ":" + $scope.port + "/ls",
        pattern: '*',
        start: function(stream) {
            // handle to the stream
            $scope.stream = stream;
            $scope.streamStatus = 'started';
        },
        headers: {
            Authorization: 'Basic '  + $rootScope.globals.currentUser['authdata']
        },
        done: function() {
            $scope.streamStatus = 'done';
        }
    }).then(function() {
        // finished loading
    }, function(error) {
      console.log(error);
        // handle errors
    }, function(node) {
        // node received
        console.log(node);
        $scope.myData.push(node);
    });

当我检查请求时,我得到以下成功的响应:

data
index.js
license
node_modules
npm-debug.log
package.json
readme.md
routes
test.js

但是双簧管似乎不想处理这个。下面是我在客户端得到的错误:

Object {statusCode: undefined, body: undefined, jsonBody: undefined, thrown: Error: Non-whitespace before {[.
Ln: 1
Col: 1
Chr: d
    at Error (native)
    at c (http://www.samh…}body: undefinedjsonBody: undefinedstatusCode: undefinedthrown: Error: Non-whitespace before {[.
Ln: 1
Col: 1
Chr: d
    at Error (native)
    at c (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:1633)
    at h (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:2054)
    at z (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:1233)
    at a.emit (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:7560)
    at XMLHttpRequest.j (http://localhost:8080/vendor/oboe/dist/oboe-browser.min.js:1:6314)__proto__: Object

我还尝试了JSON.stringify()- stdout,但无济于事。为什么会出现这个错误?提前感谢!

请在响应中发送一个对象

示例:res.status('yourstatuscode').send(passanobjecthere);

res.status(401).send({
message: 'Server error'
})

相关内容

  • 没有找到相关文章

最新更新