-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (36 loc) · 1.34 KB
/
server.js
File metadata and controls
42 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var express = require('express'); // eslint-disable-line node/no-missing-require
var app = express();
var expressBrowserify = require('express-browserify'); // eslint-disable-line node/no-missing-require
var dotenv = require('dotenv');
var AuthorizationV1 = require('ibm-watson/authorization/v1');
var ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
var isDev = app.get('env') === 'development';
app.get(
'/bundle.js',
expressBrowserify('public/client.js', {
watch: isDev,
debug: isDev,
})
);
app.use(express.static('public/'));
// optional: load environment properties from a .env file
dotenv.load({ silent: true });
// For local development, specify the username and password or set env properties
var ltAuthService = new AuthorizationV1({
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
});
app.get('/api/token/tone_analyzer', function (req, res) {
ltAuthService.getToken(function (err, token) {
if (err) {
console.log('Error retrieving token: ', err);
return res.status(500).send('Error retrieving token');
}
res.send(token);
});
});
var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
app.listen(port, function () {
console.log('Watson browserify example server running at http://localhost:%s/', port);
});