Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
fix: Update dependencies and node-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Nov 7, 2019
1 parent a60e722 commit fef9565
Show file tree
Hide file tree
Showing 8 changed files with 2,977 additions and 5,846 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
dist: trusty
sudo: required
node_js: 8
node_js: 12
services:
- docker
script:
Expand All @@ -22,16 +21,11 @@ before_deploy:
- npm install -g bx-blue-green
deploy:
- provider: script
script:
- bx-blue-green-travis
script: bx-blue-green-travis
on:
branch: master
repo: watson-developer-cloud/tone-analyzer-nodejs
skip_cleanup: true
- provider: script
skip_cleanup: true
script: npx semantic-release
on:
node: 8
branch: master
repo: watson-developer-cloud/tone-analyzer-nodejs
39 changes: 19 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,33 @@

require('dotenv').config({silent: true});

var express = require('express');
var app = express();
var ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const express = require('express');
const app = express();
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/auth');

const toneAnalyzer = new ToneAnalyzerV3({
version: '2019-10-10',
authenticator: new IamAuthenticator({
apikey: process.env.TONE_ANALYZER_IAM_APIKEY || 'type-key-here',
}),
url: process.env.TONE_ANALYZER_URL,
});

// Bootstrap application settings
require('./config/express')(app);

// Create the service wrapper
var toneAnalyzer = new ToneAnalyzerV3({
// If unspecified here, the TONE_ANALYZER_USERNAME and TONE_ANALYZER_PASSWORD environment properties will be checked
// or TONE_ANALYZER_IAM_APIKEY if is available
// After that, the SDK will fall back to the bluemix-provided VCAP_SERVICES environment property
// username: '<username>',
// password: '<password>',
version: '2017-09-21'
});

app.get('/', function(req, res) {
res.render('index');
});

app.post('/api/tone', function(req, res, next) {
toneAnalyzer.tone(req.body, function(err, data) {
if (err) {
return next(err);
}
return res.json(data);
});
app.post('/api/tone', async function(req, res, next) {
try {
const { result } = await toneAnalyzer.tone(req.body);
res.json(result);
} catch (error) {
next(error);
}
});

// error-handler application settings
Expand Down
4 changes: 2 additions & 2 deletions config/error-handler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = function(app) {
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
const err = new Error('Not Found');
err.code = 404;
err.message = `Path: ${req.path}, not Found`;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
var error = {
const error = {
code: err.code || 500,
error: err.error || err.message
};
Expand Down
Loading

0 comments on commit fef9565

Please sign in to comment.