Skip to content

Commit

Permalink
feat(server): Added middleware for development mode that disables cac…
Browse files Browse the repository at this point in the history
…hing of script files

This fixes an issue with the browser caching scripts belonging to a different app.
  • Loading branch information
DaftMonk committed Dec 22, 2013
1 parent 67c4ab9 commit c082c81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
13 changes: 12 additions & 1 deletion templates/express/config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions templates/express/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c082c81

Please sign in to comment.