const express = require('express') const path = require('path') const passport = require('passport') const morgan = require('morgan') const cookieParser = require('cookie-parser') const bodyParser = require('body-parser') const session = require('express-session') const flash = require('express-flash') const fileUpload = require('express-fileupload') var env = process.env.NODE_ENV || 'testing' const config = require('./config/config')[env] var app = express() app.set('port', config.app.port) app.set('views', __dirname + '/views') app.set('view engine', 'pug') app.use(morgan('combined')) app.use(cookieParser()) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({extended: false})) app.use(express.static(path.join(__dirname, 'public'))) app.use(session( { resave: true, saveUninitialized: true, secret: 'thisisasecret-thisisasecret-thisisasecret' } )) app.use(passport.initialize()) app.use(passport.session()) app.use(flash()) app.use((req, res, next) => { res.locals.errors = req.flash("error") res.locals.successes = req.flash("success") next() }) // enable files upload app.use(fileUpload({ createParentPath: true, limits: { fileSize: 1000000 // 1 MB max. file size } })) // caching disabled for every route // NOTE: Works in Firefox and Opera. Does not work in Edge app.use(function(req, res, next) { res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0') next() }) //require('./routes/routes-account')(app, config, passport, i18n); require('./routes/routes-project')(app, config, passport) // Handle 404 app.use(function (req, res, next) { //res.status(404).send('404: Page not Found', 404) res.status(404).render('./DE/404') }) // Handle 500 - any server error app.use(function (err, req, res, next) { console.error(err.stack) res.status(500).render('./DE/500', { error: err }) }) app.listen(app.get('port'), function () { console.log('Project Page listening on port ' + app.get('port')) console.log(__dirname) })