-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
53 lines (40 loc) · 1.03 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
/**
* Sets up the routing for the server, sending each
* API request to its associated controller
* @module server/api
*/
var express = require('express');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var db = require('./db.js');
var cors = require('cors');
/* * Middleware * */
module.exports = app = express();
app.use(cors());
app.use(bodyParser.json());
/* * API Routing * */
app.get('/top', function(req, res){
console.log('BEFORE');
db.getTop().then(function(data){
console.log('inside');
res.send(data);
console.log('after')
});
});
app.get('/people/*', function(req, res){
db.getPerson(req.url.slice(8)).then(function(data){
res.send(data);
});
});
// app.post('/top', function(req, res){
// db.setTop(req.body);
// res.send('OK');
// });
// app.post('/people', function(req, res){
// db.setPerson(req.body.firstName, req.body.details);
// res.send('OK');
// });
var port = process.env.PORT || 9100;
app.listen(port, function() {
console.log('listening on', port);
});