-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (38 loc) · 1.16 KB
/
app.js
File metadata and controls
51 lines (38 loc) · 1.16 KB
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
44
45
46
47
48
49
50
51
'use strict'
// Required modules.
const path = require('path')
const express = require('express')
const http = require('http')
const bbt = require('beebotte')
const app = express()
// Replace by your ACCESS and SECRET Keys
const bclient = new bbt.Connector({
apiKey: 'YOUR_API_KEY',
secretKey: 'YOUR_SECRET_KEY',
})
// configure Express
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', function (req, res, next) {
res.redirect('/track.html')
})
app.get( '/auth', function (req, res, next) {
const channel = req.query.channel
const resource = req.query.resource || '*'
const ttl = req.query.ttl || 0
const read = req.query.read === 'true'
const write = req.query.write === 'true'
const sid = req.query.sid
if (!sid || !channel) {
return res.status(403).send('Unauthorized')
}
const retval = bclient.sign(
// string to sign
`${sid}:${channel}.${resource}:ttl=${ttl}:read=${read}:write=${write}`
)
return res.send(retval)
})
const server = app.listen(8080, function () {
const host = server.address().address
const port = server.address().port
console.log('presentit listening at http://%s:%s', host, port)
})