-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (31 loc) · 949 Bytes
/
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
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
const model = require('./model-datastore');
app.use('/', express.static(`${__dirname}/client/build`));
app.get('/api/planets', (req, res) => {
var livable = (req.query.livable == 'true');
var farmable = (req.query.farmable == 'true');
var investment = (req.query.investment == 'true');
var planets = model.getPlanets(livable, farmable, investment, (err, planets) => {
if (err) {
console.error('ERROR:', err);
return;
} else {
res.json(planets);
}
});
});
app.get('/api/planets/:id', (req, res) => {
var key = Number(req.params.id);
var planet = model.getPlanet(key, (err, planet) => {
if (err) {
console.error('ERROR:', err);
return;
} else {
res.json(planet);
}
});
});
app.listen(port, () => console.log(`Listening on port ${port}`));