-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.js
82 lines (67 loc) · 1.85 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
/**
* Module dependencies.
*/
var express = require('express')
, hulk = require('hulk-hogan')
, cluster = require('cluster')
, nconf = require('nconf')
, lingua = require('lingua');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.register('.html', hulk);
app.set('view options',{layout:true});
app.use(lingua(app, {
defaultLocale : 'he',
path : __dirname + '/i18n'
}));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
function init_dev() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}
app.configure('local', function(){
console.log('** using local oknesset server');
app.enable('local');
init_dev();
});
app.configure('standalone', function(){
console.log('**standalone');
app.enable('standalone');
init_dev();
});
app.configure('development', function(){
console.log('**dev');
init_dev();
});
app.configure('production', function(){
console.log('**prod');
app.disable('view cache');
app.use(express.errorHandler());
});
// Routes
var routes = require('./routes')(app);
app.get('/:controller/:action/:id', routes.get);
app.get('/:controller/:id', routes.get);
app.get('/:controller', routes.get);
app.get('/api/v2/*', routes.api);
app.get('/', routes.index);
// Run as cluster (node.js is web scale!)
if (cluster.isMaster) {
// Fork workers.
var numCPUs = require('os').cpus().length;
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
console.log("worker: %s", process.env.NODE_WORKER_ID);
app.listen(nconf.get('port') || 3000);
}