Skip to content

Commit e5f57f3

Browse files
meteormanagedrwjblue
authored andcommitted
Basic gzip compression with express. (#15)
* Add option to README for gzip compression. Pass along option to worker and express server. * Added 'compression' requirement to package.json.
1 parent 953f9d5 commit e5f57f3

5 files changed

Lines changed: 13 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Put the following in a `server.js` file:
3535
const FastBootAppServer = require('fastboot-app-server');
3636

3737
let server = new FastBootAppServer({
38-
distPath: 'dist'
38+
distPath: 'dist',
39+
gzip: true // Optional - Enables gzip compression.
3940
});
4041

4142
server.start();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"aws-sdk": "^2.3.4",
2727
"basic-auth": "^1.0.3",
2828
"chalk": "^1.1.3",
29+
"compression": "^1.6.2",
2930
"express": "^4.13.3",
3031
"fastboot": "^1.0.0-rc.0",
3132
"fastboot-express-middleware": "^1.0.0-rc.3",

src/express-http-server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ class ExpressHTTPServer {
1212
this.username = options.username;
1313
this.password = options.password;
1414
this.cache = options.cache;
15+
this.gzip = options.gzip || false;
1516

1617
this.app = express();
18+
if (options.gzip) {
19+
this.app.use(require('compression')());
20+
}
1721
}
1822

1923
serve(middleware) {

src/fastboot-app-server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class FastBootAppServer {
1515
this.notifier = options.notifier;
1616
this.cache = options.cache;
1717
this.ui = options.ui;
18-
18+
this.gzip = options.gzip || false;
19+
1920
if (!this.ui) {
2021
let UI = require('./ui');
2122
this.ui = new UI();
@@ -27,7 +28,8 @@ class FastBootAppServer {
2728
this.worker = new Worker({
2829
ui: this.ui,
2930
distPath: this.distPath || process.env.FASTBOOT_DIST_PATH,
30-
cache: this.cache
31+
cache: this.cache,
32+
gzip: this.gzip
3133
});
3234

3335
this.worker.start();

src/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class Worker {
1010
this.httpServer = options.httpServer;
1111
this.ui = options.ui;
1212
this.cache = options.cache;
13-
13+
this.gzip = options.gzip || false;
14+
1415
if (!this.httpServer) {
1516
this.httpServer = new ExpressHTTPServer({
1617
ui: this.ui,

0 commit comments

Comments
 (0)