forked from rgarcia/dochub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (65 loc) · 2.32 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
define([
'express',
'module',
'path',
'./config',
'fs'
], function (express, module, path, config, fs) {
var app = null;
console.log(global.process.env);
// can't serve cache manifest w/ express static since it doesn't set the header
// correctly. so we'll load the file once, keep it in memory, serve it up manually
var filename = module.uri;
var manifestFilename = 'dochub.appcache';
var manifest = null;
fs.readFile(path.dirname(filename) + '/static/' + manifestFilename, function(err,buf) {
if(err)
throw(err);
manifest = {
headers:{
'Content-Type' : 'text/cache-manifest',
'Content-Length': buf.length,
// 'Cache-Control' : 'public, max-age=' + 60*60 // do we need this caching?
},
body: buf
};
});
return {
initialize: function() {
if ( app ) return;
console.log('INITIALIZING APP');
app = express.createServer();
app.listen(config.app_port);
app.configure(function() {
app.use(express.logger({ format: ':method :url :status' }));
app.use(function(req, res, next) {
// overrides for coda
var coda_overrides = {
'/': '/coda/',
'/css/bootstrap-responsive.css': '/coda/css/bootstrap-responsive.css',
'/css/bootstrap-responsive.min.css': '/coda/css/bootstrap-responsive.min.css',
'/css/bootstrap.css': '/coda/css/bootstrap.css',
'/css/bootstrap.min.css': '/coda/css/bootstrap.min.css',
'/js/views/fullwindow.js': '/coda/js/views/fullwindow.js',
'/templates/toc.html': '/coda/templates/toc.html'
};
if (coda_overrides[req.url] && /Coda/.test(req.headers['user-agent'])) {
req.url = coda_overrides[req.url];
}
next();
});
// preempt static to serve up cache manifest
app.get("/" + manifestFilename, function(req, res){
res.writeHead(200,manifest.headers);
res.end(manifest.body);
});
var staticDir = path.dirname(filename) + '/static';
console.log('initializing static: ' + staticDir);
app.use(express.static(staticDir));
app.use(express.bodyParser());
app.use(express.methodOverride());
console.log('dochub now running on port ' + config.app_port);
});
},
};
});