app.js 2.23 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
const express = require('express')
2
const path = require('path')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
3
//const passport = require('passport')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
4
5
6
7
8
const morgan = require('morgan')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const session = require('express-session')
const flash = require('express-flash')
9
const fileUpload = require('express-fileupload')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
10
11
const helmet = require('helmet')
const compression = require('compression')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
12

Rosanny Sihombing's avatar
Rosanny Sihombing committed
13
var env = process.env.NODE_ENV || 'testing'
Rosanny Sihombing's avatar
Rosanny Sihombing committed
14
15
16
17
18
19
const config = require('./config/config')[env]

var app = express()

app.set('port', config.app.port)
app.set('views', __dirname + '/views')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
20
21
22
23
app.set('view engine', 'pug')

app.use(helmet())
app.use(compression())
Rosanny Sihombing's avatar
Rosanny Sihombing committed
24
25
26
27
28
29
30
31
32
33
34
35
36
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'
    }
))

Rosanny Sihombing's avatar
Rosanny Sihombing committed
37
38
//app.use(passport.initialize())
//app.use(passport.session())
39

Rosanny Sihombing's avatar
Rosanny Sihombing committed
40
41
42
43
44
45
app.use(flash())
app.use((req, res, next) => {
    res.locals.errors = req.flash("error")
    res.locals.successes = req.flash("success")
    next()
})
46
47
48
49
50
51
52
// enable files upload
app.use(fileUpload({
    createParentPath: true,
    limits: { 
      fileSize: 1000000 // 1 MB max. file size
    }
}))
Rosanny Sihombing's avatar
Rosanny Sihombing committed
53
54
55
56
57
58
59
60
// 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);
Rosanny Sihombing's avatar
Rosanny Sihombing committed
61
62
//require('./routes/routes-project')(app, config, passport)
require('./routes/routes-project')(app, config)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  
// 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)
})