-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 952 Bytes
/
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
const { getImage, getVideo } = require('./helpers/Scapper');
const app = require('express')();
const cors = require('cors');
const bodyParser = require('body-parser')
const jsonParser = bodyParser.json();
app.use(cors({
origin: '*',
methods: ['GET','POST','DELETE','UPDATE','PUT','PATCH','OPTIONS']
}));
app.get('/', (req, res) => {
res.send("Hello World");
})
app.post('/getImage', jsonParser, async (req, res)=>{
const {url} = req.body;
const image = await getImage(url);
const response = {
success: true,
media: image
};
res.status(200).json(response);
})
app.post('/getVideo', jsonParser, async (req, res)=>{
const {url} = req.body;
const videos = await getVideo(url);
const response = {
success: true,
media: videos
};
res.status(200).json(response);
})
const port = process.env.PORT || 8080;
app.listen(port, ()=> console.log(`App Listening on port ${port}`))