-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (51 loc) · 1.27 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('dotenv').config();
const express = require('express');
const app = express();
const cors = require('cors');
app.use(cors());
app.use(express.static('public'));
//set up vimeo client
const Vimeo = require('vimeo').Vimeo;
const client = new Vimeo(process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
process.env.ACCESS_TOKEN);
// get info for single video
app.get('/api/videos/:id', (req,res) => {
client.request({
path: `videos/${req.params.id}`,
query: {
fields: 'uri,name,description,duration'
}
}, function(error, body, status_code, headers) {
if (error) {
console.log(error);
} else {
res.json(body);
}
})
})
// get videos from search
app.get('/api/search/:query', (req,res) => {
client.request({
path: `/videos`,
query: {
page: 1,
per_page: 10,
fields: 'uri,name,description,duration',
query: req.params.query
}
}, function(error, body, status_code, headers) {
if (error) {
console.log(error);
} else {
res.json(body);
}
})
})
// home route
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
})
const port = process.env.PORT || 5000;
app.listen(port);
console.log(`Server listening on ${port}`);