-
Notifications
You must be signed in to change notification settings - Fork 4
/
middleman.js
40 lines (31 loc) · 1.14 KB
/
middleman.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
// Set this up on Gomix
const fitbitClientID = ''
const locationOfThisScript = 'http://myserver.example.com'
const querystring = require('querystring')
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded())
const server = app.listen(process.env.PORT)
const io = require('socket.io')(server)
app.post('/receive', (request, response) => {
console.log('request received', request.body.Body)
io.sockets.emit('sms', request.body)
response.sendStatus(200)
})
app.get('/fitbit/auth', (request, response) => {
let query = querystring.stringify({
response_type: 'code',
client_id: fitbitClientID,
redirect_uri: `${locationOfThisScript}/fitbit/auth/callback`,
scope: ['activity', 'heartrate', 'location', 'nutrition', 'profile', 'settings', 'sleep', 'social', 'weight'].join(' '),
expires_in: 10 * 365 * 24 * 60 * 60
})
response.redirect(`https://www.fitbit.com/oauth2/authorize?${query}`)
})
app.get('/fitbit/auth/callback', (request, response) => {
response.send(request.query.code)
})
io.on('connection', (socket) => {
console.log('new connection')
})