-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
57 lines (38 loc) · 1.3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Author: Oliver Rodriguez
// Modules to import
const express = require("express");
const rp = require("request-promise");
const cfenv = require("cfenv");
const app = express();
const server = require("http").createServer(app);
const io = require('socket.io')(server);
//Import Watson Developer Cloud SDK
// Import service credentials
// Get the environment variables from Cloud Foundry
const appEnv = cfenv.getAppEnv();
// Serve the static files in the /public directory
app.use(express.static(__dirname + '/public'));
// Create the Conversation object
// Create the Discovery object
// start server on the specified port and binding host
server.listen(appEnv.port, '0.0.0.0', function() {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});
io.on('connection', function(socket) {
console.log('a user has connected');
// Handle incomming chat messages
socket.on('chat message', function(msg) {
console.log('message: ' + msg);
io.emit('chat message', "you: " + msg);
/*****************************
Send text to Conversation
******************************/
});
});
app.get('/', function(req, res){
res.sendFile('index.html');
});
/*****************************
Function Definitions
******************************/