forked from ric03uec/nodeblox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
89 lines (73 loc) · 2.11 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
'use strict';
/**
* Module dependencies.
*/
var express = require('express');
var util = require('util');
var config = require('./config');
var Logger = require('devnull');
var logger = new Logger({namespacing : 0});
var mongoose = require('mongoose');
var RedisStore = require('connect-redis')(express);
var redis = require('redis');
var path = require('path');
var http = require('http');
var app = express();
mongoose.connect('mongodb://localhost/' + config.dbname);
/**
* Application Global Configuration
*/
app.configure(function(){
app.set('views', __dirname + '/views');
app.enable('jsonp callback');
app.set('view engine', 'jade');
app.set('view options', {layout : false});
app.use(express.static(path.join(__dirname + '/public')));
});
/**
* Application environment(s) Configuration
*/
app.configure('development', function(){
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret : 'devadotD'
}));
app.use(express.methodOverride());
app.use(function(req, res, next){
res.locals.session = req.session;
next();
});
app.use(app.router);
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('stage', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
//use redis store witht the following configuration
//also run r.js here
var redisClient = redis.createClient();
app.use(express.bodyParser());
app.use(express.cookieParser());
var sessionStore = new RedisStore({
client: redisClient
});
app.use(express.session({
store : sessionStore,
secret: 'nooneknowsthis'
}));
app.use(express.methodOverride());
app.use(function(req, res, next){
res.locals.session = req.session;
next();
});
app.use(app.router);
app.use(express.errorHandler());
});
// Routes
require('./routes')(app);
http.createServer(app).listen(config.port, function(){
logger.log("Express server listening on port " + config.port + " in environment: " + app.settings.env);
});
module.exports = app;