diff --git a/config.template.yaml b/config.template.yaml index 30aa9429..ea40cbff 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -17,6 +17,8 @@ http: domain: 'http://localhost' # Use express-minify to minify CSS and Javascript minify: false + # Static content cache (in seconds) + cache-ttl: 0 # HTTPS server details https: diff --git a/lib/config.js b/lib/config.js index d244b187..8fcb37a7 100644 --- a/lib/config.js +++ b/lib/config.js @@ -26,7 +26,8 @@ var defaults = { host: "", port: 8080, domain: "http://localhost", - minify: false + minify: false, + "cache-ttl": 0 }, https: { enabled: false, diff --git a/lib/web/jade.js b/lib/web/jade.js index c8163952..e11902bb 100644 --- a/lib/web/jade.js +++ b/lib/web/jade.js @@ -32,7 +32,7 @@ function sendJade(res, view, locals) { var file = path.join(templates, view + ".jade"); var fn = jade.compile(fs.readFileSync(file), { filename: file, - pretty: true + pretty: !Config.get("http.minify") }); cache[view] = fn; } diff --git a/lib/web/webserver.js b/lib/web/webserver.js index 1a2f3135..c3b0db28 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -229,6 +229,16 @@ function handleContactPage(req, res) { }); } +function static(dir) { + dir = path.join(__dirname, dir); + return function (req, res) { + res.sendfile(req.path.replace(/^\//, ""), { + maxAge: Config.get("http.cache-ttl") * 1000, + root: dir + }); + }; +} + module.exports = { /** * Initializes webserver callbacks @@ -273,7 +283,8 @@ module.exports = { logRequest(req); next(); }); - app.use(express.static("www")); + //app.use(express.static("www")); + app.use(static(path.join("..", "..", "www"))); }, logRequest: logRequest, diff --git a/www/js/data.js b/www/js/data.js index 28efccff..d13328b8 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -62,7 +62,7 @@ var LASTCHAT = { var FOCUSED = true; var PAGETITLE = "CyTube"; var TITLE_BLINK; -var CHATSOUND = new Audio("boop.wav"); +var CHATSOUND = new Audio("/boop.wav"); var KICKED = false; var NAME = readCookie("cytube_uname"); var SESSION = readCookie("cytube_session"); diff --git a/www/js/froogaloop.min.js b/www/js/froogaloop.min.js new file mode 100644 index 00000000..16ac836a --- /dev/null +++ b/www/js/froogaloop.min.js @@ -0,0 +1,4 @@ +var Froogaloop=function(){function e(a){return new e.fn.init(a)}function h(a,c,b){if(!b.contentWindow.postMessage)return!1;var f=b.getAttribute("src").split("?")[0],a=JSON.stringify({method:a,value:c});"//"===f.substr(0,2)&&(f=window.location.protocol+f);b.contentWindow.postMessage(a,f)}function j(a){var c,b;try{c=JSON.parse(a.data),b=c.event||c.method}catch(f){}"ready"==b&&!i&&(i=!0);if(a.origin!=k)return!1;var a=c.value,e=c.data,g=""===g?null:c.player_id;c=g?d[g][b]:d[b];b=[];if(!c)return!1;void 0!== +a&&b.push(a);e&&b.push(e);g&&b.push(g);return 0b)c+=a[b];else break;2>b&&(c+="/")}k=c;return this},api:function(a,c){if(!this.element|| +!a)return!1;var b=this.element,f=""!==b.id?b.id:null,d=!c||!c.constructor||!c.call||!c.apply?c:null,e=c&&c.constructor&&c.call&&c.apply?c:null;e&&l(a,e,f);h(a,d,b);return this},addEvent:function(a,c){if(!this.element)return!1;var b=this.element,d=""!==b.id?b.id:null;l(a,c,d);"ready"!=a?h("addEventListener",a,b):"ready"==a&&i&&c.call(null,d);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,b;a:{if((b=""!==c.id?c.id:null)&&d[b]){if(!d[b][a]){b=!1;break a}d[b][a]=null}else{if(!d[a]){b= +!1;break a}d[a]=null}b=!0}"ready"!=a&&b&&h("removeEventListener",a,c)}};e.fn.init.prototype=e.fn;window.addEventListener?window.addEventListener("message",j,!1):window.attachEvent("onmessage",j);return window.Froogaloop=window.$f=e}(); diff --git a/www/js/player.js b/www/js/player.js index d75f6e50..f032e085 100644 --- a/www/js/player.js +++ b/www/js/player.js @@ -569,7 +569,9 @@ var LivestreamPlayer = function (data) { self.setVolume = function () { }; - self.init(); + waitUntilDefined(window, "swfobject", function () { + self.init(); + }); }; var TwitchTVPlayer = function (data) {