-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
128 lines (105 loc) · 3.62 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
//dependencies
var config = require('./config'),
express = require('express'),
mongoStore = require('connect-mongo')(express),
http = require('http'),
path = require('path'),
passport = require('passport'),
mongoose = require('mongoose'),
helmet = require('helmet');
//create express app
var app = express();
//keep reference to config
app.config = config;
//setup the web server
app.server = http.createServer(app);
//setup mongoose
app.db = mongoose.createConnection(config.mongodb.uri);
app.db.on('error', console.error.bind(console, 'mongoose connection error: '));
app.db.once('open', function () {
//and... we have a data store
});
//config data models
require('./models')(app, mongoose);
//setup the session store
app.sessionStore = new mongoStore({ url: config.mongodb.uri });
//config express in all environments
app.configure(function(){
//settings
app.disable('x-powered-by');
app.set('port', config.port);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('strict routing', true);
app.set('project-name', config.projectName);
app.set('company-name', config.companyName);
app.set('system-email', config.systemEmail);
app.set('crypto-key', config.cryptoKey);
app.set('require-account-verification', config.requireAccountVerification);
//smtp settings
app.set('smtp-from-name', config.smtp.from.name);
app.set('smtp-from-address', config.smtp.from.address);
app.set('smtp-credentials', config.smtp.credentials);
//twitter settings
app.set('twitter-oauth-key', config.oauth.twitter.key);
app.set('twitter-oauth-secret', config.oauth.twitter.secret);
//github settings
app.set('github-oauth-key', config.oauth.github.key);
app.set('github-oauth-secret', config.oauth.github.secret);
//facebook settings
app.set('facebook-oauth-key', config.oauth.facebook.key);
app.set('facebook-oauth-secret', config.oauth.facebook.secret);
//arcgis settings
app.set('arcgis-oauth-key', config.oauth.arcgis.key);
app.set('arcgis-oauth-secret', config.oauth.arcgis.secret);
//middleware
app.use(express.logger('dev'));
app.use(express.compress());
app.use(express.favicon(__dirname + '/public/favicon.ico'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded());
app.use(express.json());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: config.cryptoKey,
store: app.sessionStore
}));
app.use(passport.initialize());
app.use(passport.session());
helmet.defaults(app);
//response locals
app.use(function(req, res, next) {
res.locals.user = {};
res.locals.user.defaultReturnUrl = req.user && req.user.defaultReturnUrl();
res.locals.user.username = req.user && req.user.username;
next();
});
//mount the routes
app.use(app.router);
//error handler
app.use(require('./views/http/index').http500);
//global locals
app.locals.projectName = app.get('project-name');
app.locals.copyrightYear = new Date().getFullYear();
app.locals.copyrightName = app.get('company-name');
app.locals.cacheBreaker = 'br34k-01';
});
//config express in dev environment
app.configure('development', function(){
app.use(express.errorHandler());
});
//setup passport
require('./passport')(app, passport);
//route requests
require('./routes')(app, passport);
//setup utilities
app.utility = {};
app.utility.sendmail = require('drywall-sendmail');
app.utility.slugify = require('drywall-slugify');
app.utility.workflow = require('drywall-workflow');
//listen up
app.server.listen(app.get('port'), function(){
//and... we're live
});