forked from rgarcia/dochub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
84 lines (77 loc) · 2.46 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
define([
'express',
// 'mongoose',
// 'controllers/loader',
'module',
'path',
'./config',
'fs'
], function (express,/* mongoose, controllerLoader,*/ 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
};
});
var webapp_manifest = null;
fs.readFile(path.dirname(filename) + '/static/manifest.webapp', function(err,buf) {
if(err)
throw(err);
webapp_manifest = {
headers:{
'Content-Type' : 'application/x-web-app-manifest+json',
'Content-Length': buf.length,
},
body: buf
};
});
return {
initialize: function() {
if ( app ) return;
console.log('INITIALIZING APP');
app = express.createServer();
app.listen(config.app_port);
app.configure(function() {
// var db = mongoose.connect(config.mongo_uri, function(err) {
// if (err)
// throw err;
// else
// console.log('connected to ' + config.mongo_uri);
// });
app.use(express.logger({ format: ':method :url :status' }));
// preempt static to serve up cache manifest
app.get("/" + manifestFilename, function(req, res){
res.writeHead(200,manifest.headers);
res.end(manifest.body);
});
app.get("/manifest.webapp", function(req, res){
res.writeHead(200,webapp_manifest.headers);
res.end(webapp_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());
//controllerLoader.bootControllers(app);
console.log('instacss version now running on port ' + config.app_port);
});
},
getApp: function() {
return app;
},
};
});