forked from jedireza/drywall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
104 lines (85 loc) · 2.91 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
'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');
//create express app
var app = express();
//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', false);
//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);
//middleware
app.use(express.favicon(__dirname + '/public/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
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());
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
require('./utilities')(app);
//listen up
app.server.listen(app.get('port'), function(){
//and... we're live
});