2018-10-31 17:00:31 +01:00
|
|
|
var express = require('express');
|
|
|
|
var path = require('path');
|
2019-02-27 22:09:39 +01:00
|
|
|
//var favicon = require('serve-favicon');
|
2018-10-31 17:00:31 +01:00
|
|
|
var logger = require('morgan');
|
|
|
|
var cookieParser = require('cookie-parser');
|
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var session = require('express-session');
|
2019-02-27 22:09:39 +01:00
|
|
|
var MemoryStore = require('memorystore')(session);
|
2018-10-31 17:00:31 +01:00
|
|
|
var flash = require('connect-flash');
|
|
|
|
var app = express();
|
2020-07-10 00:15:00 +02:00
|
|
|
// favicon stuff
|
|
|
|
//app.use(favicon(path.join(__dirname, 'favicons', 'favicon.ico')));
|
|
|
|
|
2018-10-31 17:00:31 +01:00
|
|
|
// view engine setup
|
2019-11-22 07:36:18 +01:00
|
|
|
app.set('views', path.join(__dirname, './views'));
|
2018-10-31 17:00:31 +01:00
|
|
|
app.set('view engine', 'pug');
|
|
|
|
app.use(logger('dev'));
|
2018-11-14 17:32:35 +01:00
|
|
|
|
2019-02-27 22:09:39 +01:00
|
|
|
app.use(bodyParser.json({ limit: '50mb' }));
|
|
|
|
app.use(
|
|
|
|
bodyParser.urlencoded({
|
|
|
|
extended: false,
|
|
|
|
limit: '50mb'
|
|
|
|
})
|
|
|
|
);
|
2018-10-31 17:00:31 +01:00
|
|
|
app.use(cookieParser());
|
2019-10-12 01:10:55 +02:00
|
|
|
app.use(express.static(path.join(__dirname, '../public'), { extensions: ['html'] }));
|
2020-07-10 00:15:00 +02:00
|
|
|
|
2019-02-27 22:09:39 +01:00
|
|
|
app.use(
|
|
|
|
session({
|
|
|
|
store: new MemoryStore({
|
|
|
|
checkPeriod: 86400000 // prune expired entries every 24h
|
|
|
|
}),
|
|
|
|
secret: '1KqZ18W8KskE1iSw',
|
|
|
|
saveUninitialized: false,
|
|
|
|
resave: false,
|
|
|
|
cookie: {
|
|
|
|
maxAge: 608800000
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2018-10-31 17:00:31 +01:00
|
|
|
app.use(flash());
|
|
|
|
//sections
|
2019-11-16 18:10:05 +01:00
|
|
|
//var front = require('./routes/front/index')(session);
|
|
|
|
var dash = require('./routes/dash/index');
|
2019-11-23 19:30:34 +01:00
|
|
|
var page = require('./routes/dash/pages');
|
2019-11-29 02:17:59 +01:00
|
|
|
var settings = require('./routes/dash/settings');
|
2019-11-29 22:43:55 +01:00
|
|
|
var nav = require('./routes/dash/nav');
|
2018-10-31 17:00:31 +01:00
|
|
|
//api
|
2019-11-20 02:17:39 +01:00
|
|
|
var pages = require('./api/v1/pages');
|
2019-11-29 06:50:32 +01:00
|
|
|
var setting = require('./api/v1/settings');
|
2020-07-02 22:34:39 +02:00
|
|
|
var mailer = require('./api/v1/mailer');
|
2019-10-12 01:10:55 +02:00
|
|
|
var auth = require('./api/v1/auth');
|
2018-10-31 17:00:31 +01:00
|
|
|
// API PATHS
|
2018-12-08 19:21:48 +01:00
|
|
|
|
2019-11-20 02:17:39 +01:00
|
|
|
app.use('/api/v1/page', pages);
|
2019-11-29 06:50:32 +01:00
|
|
|
app.use('/api/v1/settings', setting);
|
2019-10-12 01:10:55 +02:00
|
|
|
app.use('/api/v1/auth', auth);
|
2020-07-02 22:34:39 +02:00
|
|
|
app.use('/api/v1/mailer', mailer);
|
2018-10-31 17:00:31 +01:00
|
|
|
// PAGES
|
2019-11-16 18:10:05 +01:00
|
|
|
app.use('/@/dashboard', dash);
|
2019-11-23 19:30:34 +01:00
|
|
|
app.use('/@/dashboard/page', page);
|
2019-11-29 02:17:59 +01:00
|
|
|
app.use('/@/dashboard/settings', settings);
|
2019-11-29 22:43:55 +01:00
|
|
|
app.use('/@/dashboard/navigation', nav);
|
2018-10-31 17:00:31 +01:00
|
|
|
// catch 404 and forward to error handler
|
2020-05-21 03:14:19 +02:00
|
|
|
app.use(function (req, res, next) {
|
2019-02-27 22:09:39 +01:00
|
|
|
var err = new Error('Not Found');
|
|
|
|
err.status = 404;
|
|
|
|
next(err);
|
2018-10-31 17:00:31 +01:00
|
|
|
});
|
|
|
|
// error handlers
|
|
|
|
// development error handler
|
|
|
|
// will print stacktrace
|
2019-02-27 22:09:39 +01:00
|
|
|
if (app.get('env') === 'development') {
|
2020-05-21 03:14:19 +02:00
|
|
|
app.use(function (err, req, res) {
|
2019-02-27 22:09:39 +01:00
|
|
|
res.status(err.status || 500);
|
2019-11-29 22:43:55 +01:00
|
|
|
res.render('error', {
|
2019-02-27 22:09:39 +01:00
|
|
|
message: err.message,
|
|
|
|
error: err
|
|
|
|
});
|
|
|
|
});
|
2018-10-31 17:00:31 +01:00
|
|
|
}
|
|
|
|
// production error handler
|
|
|
|
// no stacktraces leaked to user
|
2020-05-21 03:14:19 +02:00
|
|
|
app.use(function (err, req, res) {
|
2019-02-27 22:09:39 +01:00
|
|
|
res.status(err.status || 500);
|
2019-11-29 22:43:55 +01:00
|
|
|
res.render('error', {
|
2019-02-27 22:09:39 +01:00
|
|
|
message: err.message,
|
|
|
|
error: {}
|
|
|
|
});
|
2018-10-31 17:00:31 +01:00
|
|
|
});
|
2019-02-27 22:09:39 +01:00
|
|
|
module.exports = app;
|