This repository has been archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
162 lines (124 loc) · 4.13 KB
/
settings.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Module dependencies.
*/
var express = require('express')
, gzippo = require('gzippo')
, mongoStore = require('connect-mongodb')
, mongooseAuth = require('mongoose-auth')
, url = require('url')
, stylus = require('stylus')
exports.boot = function(app){
bootApplication(app)
}
// App settings and middleware
function bootApplication(app) {
app.configure(function(){
// set views path, template engine and default layout
app.set('views', __dirname + '/app/views')
app.set('view engine', 'jade')
app.set('view options', { layout: 'layouts/default' })
// contentFor & content view helper - to include blocks of content only on required pages
app.use(function(req, res, next){
// expose the current path as a view local
res.local('path', url.parse(req.url).pathname)
// assign content str for section
res.local('contentFor', function(section, str){
res.local(section, str)
})
// check if the section is defined and return accordingly
res.local('content', function(section){
if (typeof res.local(section) != 'undefined')
return res.local(section)
else
return ''
})
next()
})
// bodyParser should be above methodOverride
app.use(express.bodyParser())
app.use(express.methodOverride())
// cookieParser should be above session
app.use(express.cookieParser())
app.use(express.session({
secret: 'noobjs',
store: new mongoStore({
url: config.db.uri,
collection : 'sessions'
})
}))
app.use(express.logger(':method :url :status'))
app.use(express.favicon())
// routes should be at the last
// app.use(app.router)
app.use(mongooseAuth.middleware())
})
// Setup ejs views as default, with .html as the extension
//app.set('views', __dirname + '/views')
//app.register('.html', require('ejs'))
//app.set('view engine', 'html')
// Some dynamic view helpers
app.dynamicHelpers({
request: function(req){
return req
},
hasMessages: function(req){
if (!req.session) return false
return Object.keys(req.session.flash || {}).length
},
// flash messages
messages: require('express-messages'),
// dateformat helper. Thanks to gh-/loopj/commonjs-date-formatting
dateformat: function(req, res) {
return require('./lib/dateformat').strftime
},
base: function(){
return '/' == app.route ? '' : app.route // return the app's mount-point so that urls can adjust.
},
appName : function(req, res) {
return 'wowzamon'
},
slogan : function(req,res) {
return 'wowzamon'
}
})
// Use stylus for css templating
// completely optional, however
// the compile function allows you to
// define additional functions exposed to Stylus,
// alter settings, etc
function compile(str, path) {
return stylus(str)
.set('filename', path)
.set('warn', true)
.set('compress', true)
// .define('url', stylus.url({ paths: [__dirname + '/public/images'], limit:1000000 }))
}
// add the stylus middleware, which re-compiles when
// a stylesheet has changed, compiling FROM src,
// TO dest. dest is optional, defaulting to src
app.use(stylus.middleware({
debug: true
, src: __dirname + '/stylus'
, dest: __dirname + '/public'
, compile: compile
}))
// Don't use express errorHandler as we are using custom error handlers
// app.use(express.errorHandler({ dumpExceptions: false, showStack: false }))
// show error on screen. False for all envs except development
// settmgs for custom error handlers
app.set('showStackError', false)
// configure environments
app.configure('development', function(){
app.set('showStackError', true)
app.use(express.static(__dirname + '/public'))
})
// gzip only in staging and production envs
app.configure('staging', function(){
app.use(gzippo.staticGzip(__dirname + '/public'))
app.enable('view cache')
})
app.configure('production', function(){
app.use(gzippo.staticGzip(__dirname + '/public'))
// view cache is enabled by default in production mode
})
}