From a7f166a413f1158639b82245029ae9f35b46ef06 Mon Sep 17 00:00:00 2001 From: Christophe Coenraets Date: Wed, 4 Apr 2018 09:37:27 -0400 Subject: [PATCH] changes --- server/server.js | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/server/server.js b/server/server.js index ce33dbd..a9f195d 100644 --- a/server/server.js +++ b/server/server.js @@ -1,44 +1,40 @@ -let faye = require('faye'); -var pg = require('pg'); -let express = require('express'); -let app = express(); -let server = require('http').Server(app); -let notification = require('./modules/notification'); +let faye = require('faye'), + pg = require('pg'), + express = require('express'), + app = express(), + server = require('http').Server(app), + notification = require('./modules/notification'), + salesforce = require('./modules/salesforce'); app.use(express.static('www')); -app.use(express.static(path.join('www', 'build'))); -app.use(bodyParser.json()); let client = new pg.Client(process.env.DATABASE_URL); client.connect(); app.get('/property', (req, res) => { client.query('SELECT * FROM Property__c', (error, data) => { - res.json(data.rows); + res.json(data.rows); }); }); app.get('/property/:id', (req, res) => { client.query('SELECT * FROM Property__c WHERE ID=$1', [req.params.sfid], (error, data) => { - res.json(data.rows); + res.json(data.rows); }); }); -// Subscribe to Platform Event -let subscribeToPlatformEvents = () => { - let client = new faye.Client(org.oauth.instance_url + '/cometd/42.0/'); - client.setHeader('Authorization', 'OAuth ' + org.oauth.access_token); - client.subscribe('/event/Price_Change_Event__e', function(message) { - notification.push(message); - }); -}; - -let bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45}); +let bayeux = new faye.NodeAdapter({ mount: '/faye', timeout: 45 }); bayeux.attach(server); -bayeux.on('disconnect', function(clientId) { +bayeux.on('disconnect', function (clientId) { console.log('Bayeux server disconnect'); }); -let PORT = process.env.PORT || 5000; +saleforce.authenticate().then((oauth) => { + let client = new faye.Client(oauth.instance_url + '/cometd/42.0/'); + client.setHeader('Authorization', 'OAuth ' + oauth.access_token); + client.subscribe('/event/Price_Change_Event__e', function (message) { + notification.push(message); + }); +}); -server.listen(PORT, () => console.log(`Express server listening on ${ PORT }`)); \ No newline at end of file +server.listen(PORT, () => console.log(`Express server listening on ${process.env.PORT}`)); \ No newline at end of file