-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
76 lines (57 loc) · 1.89 KB
/
server.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
64
65
66
67
68
69
70
71
72
73
74
75
76
try {
// default settings
var config = require('./config/settings.js');
// load packages
var http = require('http');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var passport = require('passport');
var cookie_parser = require('cookie-parser');
var express_session = require('express-session');
// mongo connection
mongoose.Promise = global.Promise;
mongoose.connect(config.mongo.connection, { useNewUrlParser: true }, function(err) {
if (err) {
console.log(err);
}
console.log('Mongo connected');
});
// setup express
var app = express();
app.set('port', config.port);
// body JSON parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// set public path
var public_path = path.join(__dirname, 'public');
app.use(express.static(public_path));
// sessions
app.use(cookie_parser());
app.use(express_session({
secret: config.session.secret,
maxAge: config.session.maxAge,
resave: config.session.resave,
saveUninitialized: config.session.saveUninitialized
}));
// passport
app.use(passport.initialize());
app.use(passport.session());
// setup view engine
// app.set('view engine', 'pug');
// setup passport
require('./helpers/passport_init.js')(passport);
// load and setup routes
app.use('/', require('./routes/pages.js')());
app.use('/api', require('./routes/api.js')());
app.use('/parrots', require('./routes/parrots.js')());
// hook node onto ip:port
http.createServer(app).listen(app.get('port'), function() {
console.log('Running on http://localhost:' + app.get('port'));
});
}
catch (err) {
console.log(err);
throw err;
}