Skip to content
Snippets Groups Projects
Commit 9db9b1c3 authored by Markus Grigull's avatar Markus Grigull
Browse files

Add comment header to files

Rename server.js to app.js.
Add 404 and error handling middleware.
parent 941223f3
No related branches found
No related tags found
No related merge requests found
/**
* 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);
......
/**
* 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');
......
/**
* 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/',
......
/**
* 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');
......
/**
* 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');
......
/**
* 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');
......
/**
* 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');
......
/**
* 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');
......
......@@ -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",
......
/**
* 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');
......
/**
* 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');
......
/**
* 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');
......
/**
* 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 });
......
/**
* 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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment