-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
137 lines (112 loc) · 3.52 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
129
130
131
132
133
134
135
136
137
/**
* Module dependencies.
*/
/**
var io = require('./app/models/socket.js')
, http = require('http');
**/
var options = {
path: __dirname,
port:process.env.PORT || 9000,
env: process.env.NODE_ENV || "development"
};
var socket_url = "/data/www/chat/shared/tmp/sockets/app.socket",
production_env = 'production',
express = require('express'),
compression = require('compression'),
path = require('path'),
favicon = require('static-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
methodOverride = require('method-override'),
bodyParser = require('body-parser'),
flash = require('connect-flash'),
session = require('express-session'),
MongoStore = require('connect-mongo')(session),
RedisStore = require('connect-redis')(session),
route = require('./config/routes'),
app = express(),
http = require("http"),
envDev = require('./config/environments/development'),
redisConfig = require('./config/redis-config'),
mongooseConfig = require("./config/mongoose");
var mongoose = mongooseConfig.init(options)
app.locals.appVersion = '0.7.2';
app.locals.env = options.env;
if(production_env===options.env){
app.locals.jsPath = '/build'
}else{
app.locals.jsPath = '/javascripts'
}
app.use(compression());
// view engine setup
app.set('views', path.join(__dirname, 'app/views'));
app.set('view engine', 'jade');
app.use(favicon(path.join(__dirname, 'public/images/eye.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(methodOverride());
//envDev(app);
app.use(cookieParser());
app.use(session({
secret: "keyboard cat",
store: new MongoStore({mongooseConnection: mongoose.connection })
}))
/**
app.use(session({ store: new RedisStore(redisConfig[options.env]['options']),
secret: 'keyboard cat' ,
cookie : {
maxAge : 1000 * 60 * 60 * 10
}
}))**/
// app.use(session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true });
/**
app.use(session({
secret : "keyboard cat",
cookie : {
maxAge : 1000 * 60 * 60 * 24 * 365
}
}));**/
app.use(flash());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/bower_components',express.static(path.join(__dirname, 'bower_components')));
route.createRoutes(app);
/// catch 404 and forwarding to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will print stacktrace
if (options.env === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
var server = http.createServer(app).listen(options.port, function(){
console.log("Express server listening on port " + options.port);
});
/**
if(production_env===options.env){
var server = http.createServer(app).listen(socket_url, function(){
console.log("Express server listening on socket..... " );
});
}else{
}**/
module.exports = app;