From c082c81c21a9d8d6fd9fccd5001270759fb2a30f Mon Sep 17 00:00:00 2001 From: Tyler Henkel Date: Sun, 22 Dec 2013 00:49:04 -0500 Subject: [PATCH] feat(server): Added middleware for development mode that disables caching of script files This fixes an issue with the browser caching scripts belonging to a different app. --- app/index.js | 1 - templates/express/config/express.js | 13 ++++++++++++- templates/express/server.js | 5 +---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/index.js b/app/index.js index bd0bc8f96..662b0ebfe 100644 --- a/app/index.js +++ b/app/index.js @@ -439,7 +439,6 @@ Generator.prototype.serverFiles = function () { this.template('../../templates/express/api.js', 'lib/controllers/api.js'); this.template('../../templates/express/index.js', 'lib/controllers/index.js'); this.template('../../templates/express/config/express.js', 'lib/config/express.js'); - this.template('../../templates/express/config/middlewares/nocache.js', 'lib/config/middlewares/nocache.js'); }; Generator.prototype.mongoFiles = function () { diff --git a/templates/express/config/express.js b/templates/express/config/express.js index 3619bcb8a..2f014e696 100644 --- a/templates/express/config/express.js +++ b/templates/express/config/express.js @@ -5,9 +5,20 @@ var express = require('express'), module.exports = function(app) { var rootPath = path.normalize(__dirname + '/../..'); - + app.configure('development', function(){ app.use(require('connect-livereload')()); + + // Disable caching of scripts for easier testing + app.use(function noCache(req, res, next) { + if (req.url.indexOf('/scripts/') === 0) { + res.header("Cache-Control", "no-cache, no-store, must-revalidate"); + res.header("Pragma", "no-cache"); + res.header("Expires", 0); + } + next(); + }); + app.use(express.static(path.join(rootPath, '.tmp'))); app.use(express.static(path.join(rootPath, 'app'))); app.use(express.errorHandler()); diff --git a/templates/express/server.js b/templates/express/server.js index 0de900a8d..c98b24644 100644 --- a/templates/express/server.js +++ b/templates/express/server.js @@ -27,14 +27,11 @@ require('./lib/config/express')(app); var api = require('./lib/controllers/api'), index = require('./lib/controllers'); -// Middlewares -var noCache = require('./lib/config/middlewares/nocache'); - // Server Routes app.get('/api/awesomeThings', api.awesomeThings); // Angular Routes -app.get('/partials/*', noCache, index.partials); +app.get('/partials/*', index.partials); app.get('/*', index.index); // Start server