From 9db9b1c322feebc8bdd8cf78d185b8071086ec8a Mon Sep 17 00:00:00 2001 From: Markus Grigull <web@grigull.me> Date: Wed, 20 Jul 2016 12:00:28 +0200 Subject: [PATCH] Add comment header to files Rename server.js to app.js. Add 404 and error handling middleware. --- server.js => app.js | 30 ++++++++++++++++++++++++++++++ auth.js | 9 +++++++++ config.js | 9 +++++++++ models/model.js | 9 +++++++++ models/plot.js | 9 +++++++++ models/project.js | 9 +++++++++ models/user.js | 9 +++++++++ models/visualization.js | 9 +++++++++ package.json | 2 +- routes/models.js | 9 +++++++++ routes/plots.js | 9 +++++++++ routes/projects.js | 9 +++++++++ routes/users.js | 11 ++++++++++- routes/visualizations.js | 9 +++++++++ 14 files changed, 140 insertions(+), 2 deletions(-) rename server.js => app.js (62%) diff --git a/server.js b/app.js similarity index 62% rename from server.js rename to app.js index 4ae7a35..adc8a91 100644 --- a/server.js +++ b/app.js @@ -1,3 +1,12 @@ +/** + * File: app.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 04.07.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include modules var express = require('express'); var mongoose = require('mongoose'); @@ -35,6 +44,27 @@ app.use('/api/v1', visualizations); app.use('/api/v1', plots); app.use('/api/v1', models); +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// development error handler +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { message: err.message, error: err }); + }); +} + +// production error handler +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { message: err.message, error: {} }); +}); + // start the app app.listen(config.port, function() { console.log('Express server listening on port ' + config.port); diff --git a/auth.js b/auth.js index 07ed2d7..50b6a3b 100644 --- a/auth.js +++ b/auth.js @@ -1,3 +1,12 @@ +/** + * File: auth.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 26.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var jwt = require('jsonwebtoken'); diff --git a/config.js b/config.js index a0a2416..af5d65a 100644 --- a/config.js +++ b/config.js @@ -1,3 +1,12 @@ +/** + * File: config.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 23.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + module.exports = { databaseName: 'VILLAS', databaseURL: 'mongodb://mongo:27017/', diff --git a/models/model.js b/models/model.js index 88fb312..6b686b2 100644 --- a/models/model.js +++ b/models/model.js @@ -1,3 +1,12 @@ +/** + * File: model.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 19.07.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var mongoose = require('mongoose'); diff --git a/models/plot.js b/models/plot.js index 2c48b0b..b94462f 100644 --- a/models/plot.js +++ b/models/plot.js @@ -1,3 +1,12 @@ +/** + * File: plot.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 28.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var mongoose = require('mongoose'); diff --git a/models/project.js b/models/project.js index b8590f5..0917855 100644 --- a/models/project.js +++ b/models/project.js @@ -1,3 +1,12 @@ +/** + * File: project.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 04.07.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var mongoose = require('mongoose'); diff --git a/models/user.js b/models/user.js index a82fe49..ec7644f 100644 --- a/models/user.js +++ b/models/user.js @@ -1,3 +1,12 @@ +/** + * File: user.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 26.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); diff --git a/models/visualization.js b/models/visualization.js index ba9e6ff..128b0a3 100644 --- a/models/visualization.js +++ b/models/visualization.js @@ -1,3 +1,12 @@ +/** + * File: visualization.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 28.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var mongoose = require('mongoose'); diff --git a/package.json b/package.json index 43afcca..118115d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "VILLASweb-backend", "version": "0.1.0", "private": true, - "main": "server.js", + "main": "app.js", "dependencies": { "bcrypt-nodejs": "^0.0.3", "body-parser": "^1.15.2", diff --git a/routes/models.js b/routes/models.js index e3053b1..08078a3 100644 --- a/routes/models.js +++ b/routes/models.js @@ -1,3 +1,12 @@ +/** + * File: models.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 19.07.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var express = require('express'); diff --git a/routes/plots.js b/routes/plots.js index fc68796..5089c32 100644 --- a/routes/plots.js +++ b/routes/plots.js @@ -1,3 +1,12 @@ +/** + * File: plots.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 28.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var express = require('express'); diff --git a/routes/projects.js b/routes/projects.js index 4ca8deb..03e4d1f 100644 --- a/routes/projects.js +++ b/routes/projects.js @@ -1,3 +1,12 @@ +/** + * File: projects.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 26.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var express = require('express'); diff --git a/routes/users.js b/routes/users.js index 83c7bb8..2a2a015 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,3 +1,12 @@ +/** + * File: users.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 26.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var express = require('express'); var jwt = require('jsonwebtoken'); @@ -19,7 +28,7 @@ router.route('/users').get(auth.validateAdminLevel(1), function(req, res) { // get all users User.find(function(err, users) { if (err) { - return res.send(err); + return next(err); } res.json({ users: users }); diff --git a/routes/visualizations.js b/routes/visualizations.js index 9ff90cb..89aec59 100644 --- a/routes/visualizations.js +++ b/routes/visualizations.js @@ -1,3 +1,12 @@ +/** + * File: visualizations.js + * Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de> + * Date: 28.06.2016 + * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + // include var express = require('express'); -- GitLab