-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
52 lines (43 loc) · 1.17 KB
/
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
44
45
46
47
48
49
50
51
52
const express = require('express')
const http = require('http')
const socketio = require('socket.io')
const bodyParser = require('body-parser')
const Instagram = require('instagram-node-lib')
const port = process.env.PORT || 8080
const static_path = './dist'
const app = express()
const server = http.Server(app)
const io = socketio(server)
if (process.env.NODE_ENV !== 'production') {
require('dotenv').load()
}
Instagram.set('client_id', process.env.CLIENT_ID)
Instagram.set('client_secret', process.env.CLIENT_SECRET)
Instagram.tags.subscribe({
object: 'tag',
object_id: 'catsofinstagram',
aspect: 'media',
callback_url: process.env.CALLBACK_URL,
type: 'subscription'
})
app.use(express.static(static_path))
app.use(bodyParser.json())
app.get('/', function (req, res) {
res.sendFile('index.html', {
root: static_path
})
})
app.get('/gimmecats', function (req, res) {
Instagram.subscriptions.handshake(req, res)
})
app.post('/gimmecats', function (req, res) {
res.send()
Instagram.tags.recent({
name: req.body[0].object_id,
complete: (data) => {
io.sockets.emit('cats', { cat: data })
}
})
})
server.listen(port)
console.log('Listening ...')