-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (33 loc) · 1.06 KB
/
app.js
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'),
app = express(),
watson = require('watson-developer-cloud'),
extend = require('util')._extend,
i18n = require('i18next');
//i18n settings
require('./config/i18n')(app);
// Bootstrap application settings
require('./config/express')(app);
// Create the service wrapper
var personalityInsights = watson.personality_insights({
version: 'v2',
username: '<username>', //Replace this with your username
password: '<password>' //Replace this with your password
});
app.get('/', function(req, res) {
res.render('index', { ct: req._csrfToken });
});
app.post('/api/profile', function(req, res, next) {
var parameters = extend(req.body, { acceptLanguage : i18n.lng() });
personalityInsights.profile(parameters, function(err, profile) {
if (err)
return next(err);
else
return res.json(profile);
});
});
// error-handler settings
require('./config/error-handler')(app);
var port = process.env.VCAP_APP_PORT || 3000;
app.listen(port);
console.log('listening at:', port);