From 1c9387a49696d5cf6a74124da183ac7946961104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 13 Nov 2020 19:10:59 +0100 Subject: [PATCH] BETTERZON-29: Reformatting Backend Code --- Backend/app.js | 20 ++++++------ Backend/bin/www | 68 ++++++++++++++++++++--------------------- Backend/routes/index.js | 6 ++-- Backend/routes/users.js | 4 +-- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Backend/app.js b/Backend/app.js index ab7aed4..07d97a9 100644 --- a/Backend/app.js +++ b/Backend/app.js @@ -15,7 +15,7 @@ app.set('view engine', 'pug'); app.use(logger('dev')); app.use(express.json()); -app.use(express.urlencoded({ extended: false })); +app.use(express.urlencoded({extended: false})); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); @@ -23,19 +23,19 @@ app.use('/', indexRouter); app.use('/users', usersRouter); // catch 404 and forward to error handler -app.use(function(req, res, next) { - next(createError(404)); +app.use(function (req, res, next) { + next(createError(404)); }); // error handler -app.use(function(err, req, res, next) { - // set locals, only providing error in development - res.locals.message = err.message; - res.locals.error = req.app.get('env') === 'development' ? err : {}; +app.use(function (err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get('env') === 'development' ? err : {}; - // render the error page - res.status(err.status || 500); - res.render('error'); + // render the error page + res.status(err.status || 500); + res.render('error'); }); module.exports = app; diff --git a/Backend/bin/www b/Backend/bin/www index 192c6f3..ae6f6d1 100644 --- a/Backend/bin/www +++ b/Backend/bin/www @@ -34,19 +34,19 @@ server.on('listening', onListening); */ function normalizePort(val) { - var port = parseInt(val, 10); + var port = parseInt(val, 10); - if (isNaN(port)) { - // named pipe - return val; - } + if (isNaN(port)) { + // named pipe + return val; + } - if (port >= 0) { - // port number - return port; - } + if (port >= 0) { + // port number + return port; + } - return false; + return false; } /** @@ -54,27 +54,27 @@ function normalizePort(val) { */ function onError(error) { - if (error.syscall !== 'listen') { - throw error; - } + if (error.syscall !== 'listen') { + throw error; + } - var bind = typeof port === 'string' - ? 'Pipe ' + port - : 'Port ' + port; + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; - // handle specific listen errors with friendly messages - switch (error.code) { - case 'EACCES': - console.error(bind + ' requires elevated privileges'); - process.exit(1); - break; - case 'EADDRINUSE': - console.error(bind + ' is already in use'); - process.exit(1); - break; - default: - throw error; - } + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } } /** @@ -82,9 +82,9 @@ function onError(error) { */ function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' - ? 'pipe ' + addr - : 'port ' + addr.port; - debug('Listening on ' + bind); + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); } diff --git a/Backend/routes/index.js b/Backend/routes/index.js index ecca96a..ab8690a 100644 --- a/Backend/routes/index.js +++ b/Backend/routes/index.js @@ -2,8 +2,10 @@ var express = require('express'); var router = express.Router(); /* GET home page. */ -router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); +router.get('/', function (req, res, next) { + res.render('index', { + title: 'Express' + }); }); module.exports = router; diff --git a/Backend/routes/users.js b/Backend/routes/users.js index 623e430..ac4689a 100644 --- a/Backend/routes/users.js +++ b/Backend/routes/users.js @@ -2,8 +2,8 @@ var express = require('express'); var router = express.Router(); /* GET users listing. */ -router.get('/', function(req, res, next) { - res.send('respond with a resource'); +router.get('/', function (req, res, next) { + res.send('respond with a resource'); }); module.exports = router;