-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (37 loc) · 1.16 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
"use strict";
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var jsonfile = require('jsonfile');
var yelp;
jsonfile.readFile(__dirname + '/server.config.json', function(err, config) {
if (err) {
console.log('Error reading server.config.json: ' + err);
process.exit(1);
}
yelp = require('yelp').createClient({
consumer_key: config.yelp.consumer_key,
consumer_secret: config.yelp.consumer_secret,
token: config.yelp.token,
token_secret: config.yelp.token_secret,
ssl: true
});
// Listen on port specified in server.config.json.
server.listen(config.port, function () {
console.log("Matthews Neighborhood Map Server listening on http://localhost:%s", config.port);
});
});
// Serve static files in /public
app.use(express.static(__dirname + '/public'));
// Listen for GET requests on /business
app.get('/business/:id', function (req, res) {
console.log("Requesting Yelp data for id: " + req.params.id);
// Get data from Yelp's API about the requested business
yelp.business(req.params.id, function (err, data) {
if (err) {
res.send(err.data);
return;
}
res.send(JSON.stringify(data));
});
});