-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.01 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
require('dotenv').config()
const express = require('express')
const axios = require('axios')
const cors = require('cors')
var path = require('path')
const app = express();
const port = process.env.PORT;
app.use(cors())
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
// Get movie details based in IMDB tt
app.get('/get', async (req, res) => {
const { data } = await axios.get(process.env.PROVIDER, {
params: {
apikey: process.env.APIKEY,
i: req.query.id,
}
});
res.json(data);
});
// Get movies matching the searched title
app.get('/search', async (req, res) => {
const { data } = await axios.get(process.env.PROVIDER, {
params: {
apikey: process.env.APIKEY,
s: req.query.title,
}
});
if (data.hasOwnProperty('Error')) {
res.json([]);
} else {
res.json(data.Search);
}
});
app.listen(port, () => {
console.log(`App listening on port ${port}!`)
});