-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (50 loc) · 1.51 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Dependencies
var application_root = __dirname;
var express = require('express');
var app = express();
var path = require('path');
var fs = require('fs');
var flash = require('connect-flash');
var mongoose = require('mongoose');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var passport = require('passport');
var models = require('./models');
// Configuring Express
app.set('view engine', 'ejs'); // set up ejs for templating
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser('secret')); // read cookies (needed for auth)
app.use(bodyParser());
// required for passport
app.use(session({
secret: 'sessionsecret',
resave: true,
saveUninitialized: true,
cookie : {
maxAge: 3600000
}
}));
app.use(flash()); // use connect-flash for flash messages stored in session
require('./config/passport')(passport);
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use("/public/", express.static(path.join(__dirname, 'public')));
var routes = require('./routes')(app, passport);
// Server
var use_port;
try {
stats = fs.lstatSync('TEST');
if (stats.isFile()) {
use_port = 3000;
}
}
catch (e) {
use_port = 80;
}
var server = app.listen(use_port, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});