Skip to content

Commit

Permalink
cleanup and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Koppenhagen authored and Danny Koppenhagen committed Nov 27, 2015
1 parent be50b58 commit 40ddeb2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
This is a service for your personal touchscreen at home. You can display and control all your home automatization functions.

## Requirements
* [Node.js](https://nodejs.org/en/)
* [Node.js](https://nodejs.org/en/) `>=5.0` ; NPM (comes with Node.js)
* [Gulp.js](http://gulpjs.com/)
* NPM (comes with Node.js)
* [MongoDB](https://www.mongodb.org/) as NoSQL Database

## Setup
Expand Down
33 changes: 24 additions & 9 deletions backend/config.example.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
exports.port = 4000; // port which the backend will run on
/**
* @desc specify the port which the app will run on
*/
exports.port = 4000

exports.shoppinglist_db = 'mongodb://localhost/shoppinglist';

/* openweather configuration */
exports.weather = {
apikey : 'YOUR_OPEN_WEATHER_DOT_COM_API_KEY', //set openweather.com API key if you have one
culture : 'de', //set the culture (de, fr, etc.)
forecastType: '' //set the forecast type (daily, etc.); or '' for 3 hours forecast
};
/**
* @desc configure pramaters for services
* @desc set a value of a service to 'false' to disable the service
* @desc set a value of a service to 'true' or to an object
* with service-specific configuration to enable a service
*/
exports.service = {
shopping: false,
/*
{
db: 'mongodb://localhost/shoppinglist'
},
*/
vbb: false,
weather: {
apikey : 'YOUR_OPEN_WEATHER_DOT_COM_API_KEY', //openweather.com API key
culture : 'de', //culture (de, fr, etc.)
forecastType: '' //forecast type (daily, etc.); or '' for 3 hours forecast
}
}
7 changes: 3 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "infoscreen_3.0",
"name": "homescreen-backend",
"version": "0.0.1",
"description": "The third version of the infoscreen",
"description": "This is a backend for homescreen project of homescreenrocks",
"main": "server.js",
"author": "Danny Koppenhagen",
"author": "Danny Koppenhagen, Tilmann Bach",
"devDependencies": {
"bluebird": "^3.0.5",
"body-parser": "^1.14.1",
"cors": "^2.7.1",
"express": "^4.13.3",
"mongoose": "^4.2.4",
"mysql": "^2.9.0",
"vbb": "^0.3.2"
}
}
2 changes: 1 addition & 1 deletion backend/routes/shoppinglist.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var mongoose = require('mongoose');
var config = require('../config.js');

mongoose.connect(config.shoppinglist_db);
mongoose.connect(config.service.shopping.db);

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
Expand Down
76 changes: 49 additions & 27 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,64 @@
/**
* @desc require packages
*/
var express = require('express');
var cors = require('cors');
var bodyParser = require('body-parser');

var shoppinglist = require('./routes/shoppinglist.js');
var vbb = require('./routes/vbb.js');
var weather = require('./routes/weather.js');

var colors = require('colors');
var app = express();
var config = require("./config.js");

//CORS middleware
var config = require('./config.js'); // require config

/**
* @desc CORS middleware
*/
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
app.use(allowCrossDomain);
app.use(bodyParser.json());

app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));

console.log('Started the following REST-services:'.yellow);
/**
* @desc shopping list routes
*/
if(config.service.shopping){
var shoppinglist = require('./routes/shoppinglist.js');
app.get('/shopping', shoppinglist.findAll);
app.get('/shopping/:id', shoppinglist.findById);
app.post('/shopping', shoppinglist.add);
app.put('/shopping/:id', shoppinglist.update);
app.delete('/shopping/:id', shoppinglist.delete);
app.delete('/shopping', shoppinglist.deleteAll);
console.log('- shopping-list'.green);
}

/* shopping list routes */
app.get('/list', shoppinglist.findAll);
app.get('/list/:id', shoppinglist.findById);
app.post('/list', shoppinglist.add);
app.put('/list/:id', shoppinglist.update);
app.delete('/list/:id', shoppinglist.delete);
app.delete('/list', shoppinglist.deleteAll);
/**
* @desc station monitor routes
*/
if(config.service.vbb){
var vbb = require('./routes/vbb.js');
app.get('/vbb/:id', vbb.getStationInfo);
console.log('- vbb'.green);
}

/**
* @desc weather routes
*/
if(config.service.weather){
var weather = require('./routes/weather.js');
app.get('/weather/:id', weather.getWeatherInfo);
console.log('- weather'.green);
}

/* station monitor routes */
app.get('/vbb/:id', vbb.getStationInfo);

/* Weather */
app.get('/weather/:id', weather.getWeatherInfo);

/**
* @desc start server
*/
app.listen(config.port);
console.log("the app will run on:",config.port);
console.log('Backend runs on Port:'.yellow, config.port);

0 comments on commit 40ddeb2

Please sign in to comment.