diff --git a/src/express-http-server.js b/src/express-http-server.js index 3bcc8193..223811d2 100644 --- a/src/express-http-server.js +++ b/src/express-http-server.js @@ -30,8 +30,12 @@ class ExpressHTTPServer { this.beforeMiddleware(app); + if (this.cache) { + app.get('/*', this.buildCacheMiddleware()); + } + if (this.gzip) { - this.app.use(require('compression')()); + app.use(require('compression')()); } if (username !== undefined || password !== undefined) { @@ -39,10 +43,6 @@ class ExpressHTTPServer { app.use(basicAuth(username, password)); } - if (this.cache) { - app.get('/*', this.buildCacheMiddleware()); - } - if (this.distPath) { app.get('/', fastbootMiddleware); app.use(express.static(this.distPath)); @@ -75,12 +75,12 @@ class ExpressHTTPServer { .then(response => { if (response) { this.ui.writeLine(`cache hit; path=${path}`); - res.send(response); + res.body = response; } else { this.ui.writeLine(`cache miss; path=${path}`); this.interceptResponseCompletion(path, res); - next(); } + next(); }) .catch(() => next()); };