HTTPHandler.prototype.handler = function (request, response) {
var file_list, default_file_list, hash, uri, site, subs, self = this;
- site = 'default';
uri = url.parse(request.url, true);
subs = uri.pathname.substr(0, 4);
- if (uri.pathname === '/all.js') {
- hash = is_cached(site,'all.js');
- if (!hash) {
- file_list = [];
- default_file_list = [];
- console.log('a');
- fs.readFile('client_backbone/manifest.json', 'utf-8', function (err, manifest) {
- console.log('b');
- var js = '';
- manifest = JSON.parse(manifest);
- _.each(manifest.js, function (file) {
- console.log(file)
- js += fs.readFileSync('client_backbone/js/' + file, 'utf-8') + '\r\n';
- });
-
- // TODO: Replace false with check for debug flag
- if (/* debug === */ false) {
- js = uglify.uglify.gen_code(uglify.uglify.ast_squeeze(uglify.uglify.ast_mangle(uglify.parser.parse(js))));
- }
-
- hash = set_cache(site, 'all.js', js);
- if (request.headers['if-none-match'] === hash) {
- response.statusCode = 304;
- } else {
- response.setHeader('Content-type', 'application/javascript');
- response.setHeader('ETag', hash);
- response.write(js);
- }
- response.end();
- });
- } else {
- if (request.headers['if-none-match'] === hash) {
- response.statusCode = 304;
- } else {
- response.setHeader('Content-type', 'application/javascript');
- response.setHeader('ETag', hash);
- response.write(get_cache(site, 'all.js'));
- }
- response.end();
- }
- } else if (uri.pathname === '/') {
- var jadefile = '';
-
- hash = is_cached(site, '/');
-
- if (!hash) {
- try {
- fs.readFile('client_backbone/index.jade', 'utf-8', function (err, str) {
- if (err) {
- console.log(err + '');
- response.end();
- } else {
- jadefile = str;
- }
- hash = set_cache('default', '/', jade.compile(jadefile, {pretty: true})());
- if (response.statusCode !== 500) {
- if (request.headers['if-none-match'] === hash) {
- response.statusCode = 304;
- } else {
- response.setHeader('Content-type', 'text/html; charset=utf-8');
- response.setHeader('ETag', hash);
- response.write(get_cache(site, '/'));
- }
- }
- response.end();
- });
-
- } catch (e) {
- console.log(e);
- response.statusCode = 500;
- response.end();
- }
- } else {
- if (request.headers['if-none-match'] === hash) {
- response.statusCode = 304;
- } else {
- response.setHeader('Content-type', 'text/html; charset=utf-8');
- response.setHeader('ETag', hash);
- response.write(get_cache(site, '/'));
- }
- response.end();
- }
- } else if ((subs === '/img') || (subs === '/css')) {
- serve_static_file.call(this, request, response);
- } else if (uri.pathname.substr(0, 10) === '/socket.io') {
+ if (uri.pathname.substr(0, 10) === '/socket.io') {
return;
} else {
- response.statusCode = 404;
- response.end();
+ serve_static_file.call(this, request, response);
}
};