Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ukchukx
Created January 21, 2020 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukchukx/d5cb795db7672c0aad246d13becec677 to your computer and use it in GitHub Desktop.
Save ukchukx/d5cb795db7672c0aad246d13becec677 to your computer and use it in GitHub Desktop.
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