Skip to content

Commit 9da05c8

Browse files
mhheiseAwk34
authored andcommitted
(fix:express): reorder static middleware (#1925)
Fixes an upstream issue in express-session or express-sequelize-session where static middleware requests: - Hit the session store, - Overwrite one another, and - Generate many new sessions. Fixes #1668.
1 parent a0b7b97 commit 9da05c8

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ var Store = expressSequelizeSession(session.Store);<% } %>
2929
export default function(app) {
3030
var env = app.get('env');
3131

32+
if (env === 'development' || env === 'test') {
33+
app.use(express.static(path.join(config.root, '.tmp')));
34+
}
35+
36+
if (env === 'production') {
37+
app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
38+
}
39+
40+
app.set('appPath', path.join(config.root, 'client'));
41+
app.use(express.static(app.get('appPath')));
42+
app.use(morgan('dev'));
43+
3244
app.set('views', config.root + '/server/views');<% if (filters.html) { %>
3345
app.engine('html', require('ejs').renderFile);
3446
app.set('view engine', 'html');<% } %><% if (filters.jade) { %>
@@ -73,14 +85,6 @@ export default function(app) {
7385
}));
7486
}
7587

76-
app.set('appPath', path.join(config.root, 'client'));
77-
78-
if ('production' === env) {
79-
app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
80-
app.use(express.static(app.get('appPath')));
81-
app.use(morgan('dev'));
82-
}
83-
8488
if ('development' === env) {
8589
app.use(require('connect-livereload')({
8690
ignore: [
@@ -92,9 +96,6 @@ export default function(app) {
9296
}
9397

9498
if ('development' === env || 'test' === env) {
95-
app.use(express.static(path.join(config.root, '.tmp')));
96-
app.use(express.static(app.get('appPath')));
97-
app.use(morgan('dev'));
9899
app.use(errorHandler()); // Error handler - has to be last
99100
}
100101
}

0 commit comments

Comments
 (0)