-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.js
73 lines (57 loc) · 1.95 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
/**
* Module dependencies.
*/
var express = require('express')
, http = require('http')
, ejs = require('ejs')
, path = require('path')
, debug = require('debug')('desckit')
, config = require('config')
global.appPath = __dirname;
/**
* Our modules
*/
var routes = require('./routes');
config.appUrl = 'http://' + process.env.COMPUTERNAME + (config.port != 80 ? ':'+config.port : '');
require('datejs');
require('./lib/desckit').useConfig(config);
routes.useConfig(config);
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || config.port || 1280);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(function(req, res, next){
req.conf = config;
debug('%s %s', req.method, req.url);
next();
});
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, '/public')));
ejs.open = '<?';
ejs.close = '?>';
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
app.get('/descks', routes.descks);
app.get('/descks/:desckName/thumbnail/:width', routes.desckThumbnail);
app.get('/descks/:desckName/display', routes.displayDesck);
app.get('/descks/:desckName/render', routes.renderDesck);
http.createServer(app).listen(app.get('port'), '0.0.0.0', function(){
debug("Express server listening on port " + app.get('port'));
console.log('Desckit is now running on port:', app.get('port'), ' - open your browser and navigate to http://localhost:' + app.get('port'));
if (process.env.DEBUG) {
// Open the base URL
// var open = require('open');
// open(config.appUrl);
}
});
module.exports = app;