2020-03-19 17:40:19 +01:00
|
|
|
const createError = require('http-errors');
|
|
|
|
const express = require('express');
|
|
|
|
const morgan = require('morgan')
|
|
|
|
const path = require('path');
|
|
|
|
const cookieParser = require('cookie-parser');
|
2018-06-28 08:47:06 +02:00
|
|
|
|
2020-03-19 17:40:19 +01:00
|
|
|
const indexRouter = require('./routes/index');
|
2018-06-28 08:47:06 +02:00
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
// view engine setup
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
|
2020-02-28 13:25:35 +01:00
|
|
|
// accept the X-Forwarded-* headers
|
|
|
|
app.set('trust proxy', true)
|
|
|
|
|
2020-03-19 17:40:19 +01:00
|
|
|
app.use(morgan('tiny'))
|
2018-06-28 08:47:06 +02:00
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
|
|
|
|
app.use('/', indexRouter);
|
|
|
|
|
|
|
|
// catch 404 and forward to error handler
|
|
|
|
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 : {};
|
|
|
|
|
|
|
|
// render the error page
|
|
|
|
res.status(err.status || 500);
|
|
|
|
res.render('error');
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|