Skip to content

Commit c082c81

Browse files
committed
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.
1 parent 67c4ab9 commit c082c81

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Diff for: app/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ Generator.prototype.serverFiles = function () {
439439
this.template('../../templates/express/api.js', 'lib/controllers/api.js');
440440
this.template('../../templates/express/index.js', 'lib/controllers/index.js');
441441
this.template('../../templates/express/config/express.js', 'lib/config/express.js');
442-
this.template('../../templates/express/config/middlewares/nocache.js', 'lib/config/middlewares/nocache.js');
443442
};
444443

445444
Generator.prototype.mongoFiles = function () {

Diff for: templates/express/config/express.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ var express = require('express'),
55

66
module.exports = function(app) {
77
var rootPath = path.normalize(__dirname + '/../..');
8-
8+
99
app.configure('development', function(){
1010
app.use(require('connect-livereload')());
11+
12+
// Disable caching of scripts for easier testing
13+
app.use(function noCache(req, res, next) {
14+
if (req.url.indexOf('/scripts/') === 0) {
15+
res.header("Cache-Control", "no-cache, no-store, must-revalidate");
16+
res.header("Pragma", "no-cache");
17+
res.header("Expires", 0);
18+
}
19+
next();
20+
});
21+
1122
app.use(express.static(path.join(rootPath, '.tmp')));
1223
app.use(express.static(path.join(rootPath, 'app')));
1324
app.use(express.errorHandler());

Diff for: templates/express/server.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ require('./lib/config/express')(app);
2727
var api = require('./lib/controllers/api'),
2828
index = require('./lib/controllers');
2929

30-
// Middlewares
31-
var noCache = require('./lib/config/middlewares/nocache');
32-
3330
// Server Routes
3431
app.get('/api/awesomeThings', api.awesomeThings);
3532

3633
// Angular Routes
37-
app.get('/partials/*', noCache, index.partials);
34+
app.get('/partials/*', index.partials);
3835
app.get('/*', index.index);
3936

4037
// Start server

0 commit comments

Comments
 (0)