Created
April 25, 2018 13:06
-
-
Save gladchinda/3af7f2d769082fdd3af2dc553693c6b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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