I am student and learning to code and help from community is appreciated. I have hosted my code in heroku with domain name https://depionicapp.herokuapp.com/. When I am doing post request with postman I am getting Error 500
but with cloud 9 I am able to get the result.
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:
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