-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.js
82 lines (66 loc) · 2.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const cors = require('cors');
const fetch = require('cross-fetch');
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
app.get('/api/restaurants', (req, res) => {
const { lat, lng } = req.query;
console.log(req.query);
const url = `https://www.swiggy.com/dapi/restaurants/list/v5?lat=${lat}&lng=${lng}&page_type=DESKTOP_WEB_LISTING`;
fetch(url, {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log(data);
res.json(data);
})
.catch(error => {
console.error(error);
res.status(500).send('An error occurred');
});
});
app.get('/api/menu', (req, res) => {
const { lat, lng, restaurantId } = req.query;
console.log(req.query);
/* OLD SWIGGY API
const url = `https://www.swiggy.com/dapi/menu/v4/full?lat=${lat}&lng=${lng}&menuId=${menuId}`;
*/
const url = `https://www.swiggy.com/dapi/menu/pl?page-type=REGULAR_MENU&complete-menu=true&lat=${lat}&lng=${lng}&submitAction=ENTER&restaurantId=${restaurantId}`;
fetch(url, {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
res.json(data);
})
.catch(error => {
console.error(error);
res.status(500).send('An error occurred');
});
});
app.get('/', (req, res) =>{
res.json({"test":"hello instafood lovers !!! "});
})
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});