You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fipamo/brain/app.js

107 lines
2.8 KiB
JavaScript

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var MemoryStore = require('memorystore')(session)
var flash = require('connect-flash');
var theme = "default";
var app = express();
// view engine setup
app.set('views', path.join(__dirname, '../themes'));
app.set('view engine', 'pug');
//app.use(express.static(__dirname+'/content/data'));
app.use(express.static(__dirname + '../content/folio-images'));
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
//app.use(require('node-compass')({mode: 'expanded', css:'styles', sass: 'styles', project: path.join(__dirname, 'src')}));
app.use(express.static(path.join(__dirname, '../content')));
app.use(express.static(path.join(__dirname, '../themes')));
// Why Do we need this key ?
/**
app.use(session({
secret: '1KqZ18W8KskE1iSw',
saveUninitialized: false,
resave: false,
cookie:{maxAge:608800000}
}));
**/
app.use(session({
store: new MemoryStore({
checkPeriod: 86400000 // prune expired entries every 24h
}),
secret: '1KqZ18W8KskE1iSw',
saveUninitialized: false,
resave: false,
cookie: { maxAge: 608800000 }
}))
app.use(flash());
//sections
var front = require('./routes/front/index')(session);
var back = require('./routes/back/index');
//api
var folioLibrary = require('./api/content/folio');
var projectLibrary = require('./api/content/project');
var bookmarkLibrary = require('./api/content/bookmarks');
var postLibrary = require('./api/content/posts');
var mailer = require('./api/content/mailer');
// API PATHS
app.use('/api/folio', folioLibrary);
app.use('/api/projects', projectLibrary);
app.use('/api/bookmarks', bookmarkLibrary);
app.use('/api/post', postLibrary);
// PAGES
app.use('/', front);
app.use('/@/dashboard', back);
//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);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(theme+'/error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(theme+'/error', {
message: err.message,
error: {}
});
});
module.exports = app;