-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
113 lines (89 loc) · 2.89 KB
/
app.js
File metadata and controls
113 lines (89 loc) · 2.89 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Load Configuration Values
* If on Azure we will take from environment variables which are populated based on the
* App Settings. If running locally, we will provide the configuration values in a
* config.json file.
*/
var config = require('./lib/config');
config.loadFromSettingsTable(function(err) {
if (err) {
throw err;
} else {
console.log('settings loaded');
// Resume initializing application
continueInit();
}
});
function continueInit() {
/**
* Module Dependencies
*/
var express = require('express');
var http = require('http');
var path = require('path');
var passport = require('passport');
// Helper libraries
var libPassport = require('./lib/passport');
var libSocketIo = require('./lib/socketio');
var libSession = require('./lib/session');
/**
* Create and configure Express app object
*/
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(libSession.parse_cookie);
// TODO: Default session provider gives a memory leak warning - look into using something
// else for Azure/Production
app.use(express.session({
store: libSession.sessionStore,
secret: config.cookie_secret,
key: config.session_key
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(require('less-middleware')({ src: path.join(__dirname, 'public') }));
// TODO: Check where this belongs in the middleware stack. Read something about passport
// deserializing user for every request because of bad order.
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
// Attach the config object to app.locals so that Jade templates can read it.
app.locals.config = config;
/**
* Configure Passport - this is for site login as well as OAuth calls to social media
* sites.
*/
// Passport strategies
passport.use(libPassport.localStrategy);
passport.use('twitter-auth', libPassport.twitterStrategy);
passport.use('instagram-auth', libPassport.instagramStrategy);
// Passport functions to serialize and deserialize users for sessions.
passport.serializeUser(libPassport.serializeUser);
passport.deserializeUser(libPassport.deserializeUser);
/**
* Load Routes
*/
require('./routes')(app);
/**
* Start server
*/
// Instantiate server
var server = http.createServer(app);
// Attach socket.io
libSocketIo.listen(server);
// Start server
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
}