NodeJS服务器:
var exec = require('child_process').exec;
app.get('/ls', function(req, res) {
exec('ls',
function (error, stdout, stderr) {
res.send(stdout);
});
});
Angular Client(来自its 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无济于事。为什么我会收到此错误?提前谢谢!
答案 0 :(得分:0)
请在回复中发送一个对象
示例:res.status('yourstatuscode').send(passanobjecthere);
res.status(401).send({
message: 'Server error'
})