Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created April 25, 2018 13:06
Show Gist options
  • Save gladchinda/3af7f2d769082fdd3af2dc553693c6b3 to your computer and use it in GitHub Desktop.
Save gladchinda/3af7f2d769082fdd3af2dc553693c6b3 to your computer and use it in GitHub Desktop.
// server.get('*') is here ...
const chatHistory = { messages: [] };
server.post('/message', (req, res, next) => {
const { user = null, message = '', timestamp = +new Date } = req.body;
const sentimentScore = sentiment(message).score;
const chat = { user, message, timestamp, sentiment: sentimentScore };
chatHistory.messages.push(chat);
pusher.trigger('chat-room', 'new-message', { chat });
});
server.post('/messages', (req, res, next) => {
res.json({ ...chatHistory, status: 'success' });
});
// server.listen() is here ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment