-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (35 loc) · 981 Bytes
/
server.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
36
37
38
39
40
41
42
43
require('dotenv').config()
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const app = express()
const Pusher = require('pusher')
const pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.PUSHER_CLUSTER
})
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.post('/pusher/auth', (req, res) => {
const socket_id = req.body.socket_id
const channel_name = req.body.channel_name
if(socket_id && channel_name) {
res.send(pusher.authenticate(
socket_id,
channel_name,
{user_id: socket_id, user_info: {}}
))
} else {
res.sendStatus(401)
}
})
app.get('/press/:id', (req, res) => {
pusher.trigger('gameshow', 'button', {
id: req.params.id
})
res.send("done")
})
app.get('/', (req, res) => res.send("HELLO"))
app.listen(process.env.PORT || 3000)