Created
January 21, 2020 20:18
-
-
Save ukchukx/d5cb795db7672c0aad246d13becec677 to your computer and use it in GitHub Desktop.
This file contains 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
require('dotenv').config(); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const ip = require('ip'); | |
const { StreamChat } = require('stream-chat'); | |
const app = express(); | |
// Add the middlewares | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
// Initialize our Stream Chat client | |
const streamClient = new StreamChat(process.env.KC_STREAM_CHAT_KEY, process.env.KC_STREAM_CHAT_SECRET); | |
app.get('/api/kongchat/ping', (req, res) => { | |
return res.json({ message: 'pong' }); | |
}); | |
app.post('/api/kongchat/token', (req, res) => { | |
const { body: { username } } = req; | |
// generate a Stream Chat token for use by the user making the request | |
return res.json({ user: { username }, token: streamClient.createToken(username) }); | |
}); | |
app.listen(10000, () => { | |
console.log(`API running on http://${ip.address()}:10000`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment