-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (36 loc) · 1.03 KB
/
server.js
File metadata and controls
53 lines (36 loc) · 1.03 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
'use strict';
var Yelp = require('yelp');
var express = require('express'),
path = require('path'),
port = process.env.PORT || 3000,
app = express();
var yelp = new Yelp({
consumer_key: process.env.consumer_key,
consumer_secret: process.env.consumer_secret,
token:process.env.token,
token_secret: process.env.token_secret,
});
app.use(express.static('./'));
app.get('/api', function(request, response) {
// console.log('New request:', request.url);
var params = { term: 'restaurant', location: 'Seattle' };
if(request.query.location) {
params.location = request.query.location;
}
if(request.query.category_filter) {
params.category_filter = request.query.category_filter;
}
yelp.search(params)
.then(function (data) {
response.json(data);
})
.catch(function (err) {
console.error(err);
});
});
app.get('*', function(request, response){
response.sendFile(path.join(__dirname + '/index.html'));
});
app.listen(port, function() {
console.log('Server started on port ' + port + '!');
});