我是学生,学习编码并感谢社区的帮助。我在 heroku 中托管了我的代码,域名为https://depionicapp.herokuapp.com/。当我与邮递员进行发布请求时,我得到了错误500
,但使用 cloud 9 我能够得到结果。
var http = require('http');
var bodyParser = require("body-parser")
var vision = require('@google-cloud/vision');
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).
var express = require('express');
var router = express();
var visionClient = vision({
projectId: 'ionic-face-api',
keyFilename: './ionic.json'
});
router.use(bodyParser.urlencoded({extended: false }));
router.use(bodyParser.json());
router.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var server = http.createServer(router);
router.post('/info', function(req, res) {
var text = req.body.text;
console.log(text)
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var tone_analyzer = new ToneAnalyzerV3({
username: 'username',
password: 'password',
version_date: '2016-05-19'
});
tone_analyzer.tone({
text: text
}, function(err, tone) {
if (err)
console.log(err);
else
res.send((JSON.stringify(tone, null, 2)));
});
});
邮差:
Postman request: https: //depionicapp.herokuapp.com/info
Content - Type: application / json
Body I am sending from postman
{"text": "I am good.....blah blah..." }// Error 500