-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
95 lines (74 loc) · 2.04 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
var express = require('express')
, http = require('http')
, path = require('path')
, favicon = require('serve-favicon')
, logger = require('morgan')
, cookieParser = require('cookie-parser')
, bodyParser = require('body-parser')
, methodOverride = require('method-override')
, session = require('cookie-session')
, swig = require('swig')
, errorHandler = require('errorhandler')
, compress = require('compression')
var app = express();
app.engine('html', swig.renderFile);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.enable('trust proxy');
// app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(compress({
memLevel: 3,
level: 3
}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
key: 'whiteboard',
secret: 'this-should-be-put-somewhere-else',
proxy: true
}));
app.use(methodOverride());
var env = process.env.NODE_ENV || 'development';
switch (env) {
case 'production':
app.set('view cache', true);
app.use(function(err, req, res, next){
res.status(404).render('error');
});
break;
case 'test':
// app.use(logger('dev'));
app.use(errorHandler({
dumpExceptions : true,
showStack : true
}));
app.set('view cache', false);
break;
default:
app.use(logger('dev'));
app.use(errorHandler({
dumpExceptions : true,
showStack : true
}));
app.set('view cache', false);
break;
}
app.use(express.static('public'));
// Routes
app.get('/', function(req, res){
res.render('index.html');
});
var faye = require('./faye')
// Get params
var argv = require('optimist').argv;
// port
var port = argv.port || 4000;
var server = app.listen(port, function() {
console.log('Express server listening on port ', server.address().port);
faye.attach(server);
console.log("Faye Server listening on port: " + port);
console.log("Faye is mounted to /faye");
});