Add appcache support

This commit is contained in:
Lance Stout 2013-10-11 22:39:30 -07:00
parent 5a9bee42d5
commit 8abaef6f04
5 changed files with 64 additions and 10 deletions

View File

@ -1,6 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<head manifest="/manifest.cache">
<title>Otalk</title>
<link rel="stylesheet" type="text/css" href="#{cssFileName}" />
<script src="#{jsFileName}"></script>

View File

@ -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:

19
public/x-manifest.cache Normal file
View File

@ -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:

View File

@ -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