diff --git a/clientapp/template.html b/clientapp/templates/main.html similarity index 91% rename from clientapp/template.html rename to clientapp/templates/main.html index 6cc52e4..e9b3ae5 100644 --- a/clientapp/template.html +++ b/clientapp/templates/main.html @@ -1,6 +1,6 @@ - + Otalk diff --git a/clientapp/templates/misc/manifest.cache b/clientapp/templates/misc/manifest.cache new file mode 100644 index 0000000..15574b3 --- /dev/null +++ b/clientapp/templates/misc/manifest.cache @@ -0,0 +1,19 @@ +CACHE MANIFEST +# #{version} + +CACHE: +#{jsFileName} +#{cssFileName} + +images/logo.png +images/icon_128x128.png + +js/zepto.js +js/login.js +js/logout.js + +NETWORK: +* + +FALLBACK: + diff --git a/public/x-manifest.cache b/public/x-manifest.cache new file mode 100644 index 0000000..fdaba23 --- /dev/null +++ b/public/x-manifest.cache @@ -0,0 +1,19 @@ +CACHE MANIFEST +# 0.0.1 1381556294101 + +CACHE: +/app.js +/styles.css + +images/logo.png +images/icon_128x128.png + +js/zepto.js +js/login.js +js/logout.js + +NETWORK: +* + +FALLBACK: + diff --git a/public/manifest.webapp b/public/x-manifest.webapp similarity index 100% rename from public/manifest.webapp rename to public/x-manifest.webapp diff --git a/server.js b/server.js index e1e6e48..5bdfbef 100644 --- a/server.js +++ b/server.js @@ -8,6 +8,7 @@ var templatizer = require('templatizer'); var app = express(); + app.use(express.compress()); app.use(express.static(__dirname + '/public')); if (!config.isDev) { @@ -19,7 +20,7 @@ app.use(helmet.contentTypeOptions()); var clientApp = new Moonboots({ main: __dirname + '/clientapp/app.js', - templateFile: __dirname + '/clientapp/template.html', + templateFile: __dirname + '/clientapp/templates/main.html', developmentMode: config.isDev, libraries: [ __dirname + '/clientapp/libraries/zepto.js', @@ -30,15 +31,25 @@ var clientApp = new Moonboots({ stylesheets: [ __dirname + '/public/css/otalk.css' ], - server: app, - beforeBuild: function () { - if (config.isDev) { - var clientFolder = __dirname + '/clientapp'; - templatizer(clientFolder + '/templates', clientFolder + '/templates.js'); - } - } + server: app }); +if (config.isDev) { + clientApp.config.beforeBuild = function () { + var clientFolder = __dirname + '/clientapp'; + templatizer(clientFolder + '/templates', clientFolder + '/templates.js'); + + var pkginfo = JSON.parse(fs.readFileSync('./package.json')); + var cacheManifest = fs.readFileSync('clientapp/templates/misc/manifest.cache', 'utf-8'); + cacheManifest = cacheManifest + .replace('#{version}', pkginfo.version + ' ' + Date.now()) + .replace('#{jsFileName}', '/' + clientApp.jsFileName()) + .replace('#{cssFileName}', '/' + clientApp.cssFileName()); + + fs.writeFileSync('./public/x-manifest.cache', cacheManifest); + }; +} + app.set('view engine', 'jade'); app.get('/login', function (req, res) { @@ -56,7 +67,12 @@ app.get('/oauth/callback', function (req, res) { app.get('/manifest.webapp', function (req, res) { res.set('Content-Type', 'application/x-web-app-manifest+json'); - res.sent(fs.readFileSync('public/manifest.webapp')); + res.send(fs.readFileSync('./public/x-manifest.webapp')); +}); + +app.get('/manifest.cache', function (req, res) { + res.set('Content-Type', 'text/cache-manifest'); + res.send(fs.readFileSync('./public/x-manifest.cache')); }); // serves app on every other url