-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (45 loc) · 1.41 KB
/
server.js
File metadata and controls
56 lines (45 loc) · 1.41 KB
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
const express = require('express')
const app = express();
const PORT = '3232';
const request = require('request');
const API_KEY = "fFoHEGbf5qO3BdOMbgSY174VNDVnntD3kiyiznj5tUnCpTLvQICJwcfKqKbuHm9yaJRjP0hs2K73gHO1es1X3faeCtFc80fWZ6NwnDV9R2FeGN5qq5jI8Ku1EjydW3Yx";
function clear_console(){
console.log('\033[2J');
}
app.get("/search/:search_term/:location", function(req, res){
const MAX_DISTANCE = 22530;
var search_term = req.params.search_term;
var location = req.params.location;
var query = {
url : "https://api.yelp.com/v3/businesses/search?location=" + location + '&term=' + search_term + '&limit=50&radius=' + MAX_DISTANCE,
headers : {
'Authorization' : 'Bearer ' + API_KEY
}
};
request(query, function(err, response, body){
if(err){res.json(error)}
else{
var jsonBody = JSON.parse(body);
var venues = jsonBody.businesses;
res.json(venues);
}
})
})
app.get("/event_search/:location", function(req, res){
var location = req.params.location;
var query = {
url : "https://api.yelp.com/v3/events?location=" + location,
headers : {
'Authorization' : 'Bearer ' + API_KEY
}
}
request(query, function(err, response, body){
if(err){req.json(err)}
else{
var jsonBody = JSON.parse(body);
var events = jsonBody.events;
res.json(events);
}
})
})
app.listen(PORT, () => console.log("Server Located on Port " + PORT));