2018-08-10 19:25:29 +03:00
|
|
|
const createError = require('http-errors');
|
|
|
|
const express = require('express');
|
|
|
|
const path = require('path');
|
|
|
|
const cookieParser = require('cookie-parser');
|
|
|
|
const logger = require('morgan');
|
2018-10-07 19:15:10 +03:00
|
|
|
const rcParser = require('./utils/rcparser');
|
2018-08-17 13:58:44 +03:00
|
|
|
const routes = require('./routes');
|
2018-08-10 19:25:29 +03:00
|
|
|
|
|
|
|
const app = express();
|
2018-10-07 19:15:10 +03:00
|
|
|
const config = rcParser.getConfiguration();
|
|
|
|
|
|
|
|
app.locals.config = config;
|
2018-08-10 19:25:29 +03:00
|
|
|
|
|
|
|
// view engine setup
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
app.set('view engine', 'twig');
|
2018-09-19 01:47:32 +03:00
|
|
|
require('./utils/twig');
|
2018-08-10 19:25:29 +03:00
|
|
|
|
|
|
|
app.use(logger('dev'));
|
|
|
|
app.use(express.json());
|
Authentication (#22)
* Authorization added
* added secret to password, md5 hashing, removed promise from verifyToken, deleted links when not authorized
* added dbinsert script
* turned verifyToken to middleware, added description for dbinsert, added hidden csrf field in auth form
* added middlewares, user model and controller
* JSDoc fix
* wrong password processing fix
* added comments to dbinsert script, moved salt and passHash to singe db doc
* Moved salt to .env, upgradedscript for generating password was, fixed comments and JSDoc
* Deleted using salt (now user is only one), changed verifying password to bcrypt.compare, added httpyOnly property to jwt cookie
2019-03-06 13:22:57 +03:00
|
|
|
app.use(express.urlencoded({ extended: true }));
|
2018-08-10 19:25:29 +03:00
|
|
|
app.use(cookieParser());
|
2018-09-07 19:24:09 +03:00
|
|
|
app.use(express.static(path.join(__dirname, '../public')));
|
2018-08-10 19:25:29 +03:00
|
|
|
|
2018-08-17 13:58:44 +03:00
|
|
|
app.use('/', routes);
|
2018-08-10 19:25:29 +03:00
|
|
|
// catch 404 and forward to error handler
|
2018-08-17 13:58:44 +03:00
|
|
|
app.use(function (req, res, next) {
|
2018-08-10 19:25:29 +03:00
|
|
|
next(createError(404));
|
|
|
|
});
|
|
|
|
|
|
|
|
// error handler
|
2018-08-17 13:58:44 +03:00
|
|
|
app.use(function (err, req, res, next) {
|
2018-08-10 19:25:29 +03:00
|
|
|
// 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');
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|