-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 876 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const { simple, private } = require('./helpers/getToken');
const app = express();
//using middlewares
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '/public')));
function serveFile(name) {
return path.join(__dirname + `/views/${name}.html`);
}
app.get('/', (req, res) => res.sendFile(serveFile('index')));
app.post('/centrifuge/refresh', (req, res) =>
res.status(200).json({
status: 200,
token: simple
})
);
app.post('/centrifuge/subscribe', (req, res) =>
res.json({
channels: req.body.channels.map(channel => ({
channel: channel,
token: private(req.body.client, channel)
}))
})
);
app.listen(3000, () => console.log('server is up at 3000'));