Skip to content

Commit

Permalink
extend app.js prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
felixebert committed Jun 13, 2015
1 parent 14bcb61 commit bba163c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
36 changes: 32 additions & 4 deletions node-backend/app.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
var GeoJSON = require('mongoose-geojson-schema');
var mongoose = require('mongoose');
var process = require('process');
var express = require('express');
var baucis = require('baucis');
var cors = require('cors');
mongoose.connect('mongodb://localhost/tapwater');

// define models
var Location = mongoose.model('Location', new mongoose.Schema({geoFeature: GeoJSON.Feature}));
var sampleLocation = new Location({
geoFeature: {
"type": "Feature",
"properties": {
"haertegrad": "10",
"name": "Aachener Straße"
},
"geometry": {
"type": "MultiLineString",
"coordinates": [[[9.1054195, 49.1836073], [9.1053332, 49.1833407], [9.1051728, 49.1828456], [9.1051326, 49.1828453], [9.1046133, 49.1828413]], [[9.1051326, 49.1828453], [9.1049988, 49.1830276], [9.1048492, 49.1832862]], [[9.1051728, 49.1828456], [9.1053677, 49.1827792], [9.1066049, 49.1825795]]]
}
}
});
sampleLocation.save();


var Zone = mongoose.model('Zone', {
name: String,
calcium: Number,
kalium: Number
});

var sampleZone = new Zone({
name: 'Erlenbach',
calcium: 0.8,
kalium: 0.9
});
sampleZone.save();

console.log('done');
process.exit();
// rest
baucis.rest('Zone');

// start http server
var app = express();
app.use(cors());
app.use('/api', baucis());
app.listen(8012);

app.get('/geocode', function(req, res) {
res.send("Latitude " + req.query.lat + ", Longitude " + req.query.lon + ' has the following mineral values in its tapwater: calcium 0.8, natrium 2, nitrat 5 - you have a good tapwater!');
});
3 changes: 3 additions & 0 deletions node-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"author": "",
"license": "MIT",
"dependencies": {
"baucis": "^1.3.1",
"cors": "^2.7.1",
"express": "^4.12.4",
"mongoose": "^4.0.5",
"mongoose-geojson-schema": "0.0.2"
}
Expand Down

0 comments on commit bba163c

Please sign in to comment.