-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.js
45 lines (39 loc) · 1.47 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
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, connect = require('connect')
, routeProfile = require('./routes/routeProfile')
, path = require('path')
, redis = require("redis")
, redisConfig = require('./config')
, session = require('express-session')
, redisStore = require('connect-redis')(session)
, appport = redisConfig.app.port
, sessiondbconfig = redisConfig.sessiondb;
var app = express();
var redisClient = redis.createClient(redisConfig.db.port,redisConfig.db.host,{auth_pass:'123456'});
redisClient.on("error", function(err) {
console.log(err);
});
// all environments
app.set('port', appport || process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');
app.use(require('morgan')('dev'));
app.use(require('compression')());
app.use(require('body-parser')());
app.use(require('method-override')());
app.use(require('cookie-parser')());
app.use(session({ store: new redisStore({host:sessiondbconfig.host, port:sessiondbconfig.port, pass:sessiondbconfig.pass, db:sessiondbconfig.db, prefix:'sess', ttl:3600}), secret: 'iamwaltershe' }));
//app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(require('errorhandler')());
}
routeProfile.createRoutes(app);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});