fipamo/brain/app.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-10-31 17:00:31 +01:00
var express = require('express');
var path = require('path');
//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');
var MemoryStore = require('memorystore')(session);
2018-10-31 17:00:31 +01:00
var flash = require('connect-flash');
var theme = 'default-dark';
2018-10-31 17:00:31 +01:00
var app = express();
//var request = require('request');
2018-10-31 17:00:31 +01:00
// view engine setup
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
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());
app.use(express.static(path.join(__dirname, '../public'), { extensions: ['html'] }));
//app.use(express.static(path.join(__dirname, '../content')));
//app.use(express.static(path.join(__dirname, '../themes')));
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
//var front = require('./routes/front/index')(session);
var dash = require('./routes/dash/index');
var page = require('./routes/dash/pages');
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
var pages = require('./api/v1/pages');
var setting = require('./api/v1/settings');
//var mailer = require('./api/mail/mailer');
var auth = require('./api/v1/auth');
2018-10-31 17:00:31 +01:00
// API PATHS
app.use('/api/v1/page', pages);
app.use('/api/v1/settings', setting);
//app.use('/api/mail', mailer);
app.use('/api/v1/auth', auth);
2018-10-31 17:00:31 +01:00
// PAGES
app.use('/@/dashboard', dash);
app.use('/@/dashboard/page', page);
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
//app.use('/mailer', mailer);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
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
if (app.get('env') === 'development') {
app.use(function(err, req, res) {
res.status(err.status || 500);
2019-11-29 22:43:55 +01:00
res.render('error', {
message: err.message,
error: err
});
});
2018-10-31 17:00:31 +01:00
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res) {
res.status(err.status || 500);
2019-11-29 22:43:55 +01:00
res.render('error', {
message: err.message,
error: {}
});
2018-10-31 17:00:31 +01:00
});
module.exports = app;