-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (31 loc) · 873 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
41
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const Geojson = require('geojson');
const knex = require('knex');
const postgres = knex({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : '1994',
database : 'real_estate'
}
});
const app = express();
const port = 3001;
app.use(bodyParser.json());
app.use(cors());
app.get('/', (req, res) => {
res.send('Hello World!');
})
app.get('/parcels', (req, res) => {
postgres.select('*').from('parcels')
.then(parcels => {
res.send(Geojson.parse(parcels, {Polygon: 'geometry', exclude: ['geom']}));
})
.catch(err => res.status(400).json('error getting parcels'));
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
})