嘿我正在使用bluemix并使用它来部署服务器。我在我的网页控制台上收到以下错误:无法加载资源:无法连接到服务器。
我的代码如下:
/*eslint-env node*/
var express = require('express');
var cfenv = require('cfenv');
var app = express();
app.use(express.static(__dirname + '/public'));
cfenv.getAppEnv();
var http = require('http');
var bodyParser = require('body-parser');
var watson = require('watson-developer-cloud');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.set('port', process.env.VCAP_APP_PORT || 6004);
app.set('ip', process.env.VCAP_APP_HOST || "localhost");
//Default REST Call for Testing
app.post('/hello', function(req, res) {
console.log("It comes here!" + res.statusCode);
var language_translation = watson.language_translation({
username: 'my usrename',
password: 'my password',
version: 'v2'
});
language_translation.translate({
text: req.body.message,
source: 'en',
target: req.body.language
}, function(err, translation) {
if(err) {
console.log(err);
} else {
console.log(translation);
res.send(translation.translations[0].translation);
}
});
});
app.get('/hello', function(request, response) {
console.log("Hello!");
response.send("Hello World");
});
app.listen(app.get('port'),app.get('ip'), function() {
console.log("Server is listening on port "+app.get('port')+" and ip "+app.get('ip'));
console.log("Hello Boiz!!! Printed on Screen");
});
有人可以帮帮我!!! 感谢
答案 0 :(得分:0)
我看到您正在尝试使用IBM Watson的语言翻译服务。以下是相同的示例演示:Watson Language Translation Service
希望这有帮助。