Skip to content

Commit 0af4720

Browse files
pwfisherArjan Singh
authored andcommitted
Add middleware options
1 parent ae1f556 commit 0af4720

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ following interface:
191191

192192
#### `subscribe(notify)`
193193

194-
The `subscribe()` method ony our notifier is passed a `notify` function.
194+
The `subscribe()` method on your notifier is passed a `notify` function.
195195
If you detect that a new version of your app has been deployed (whether
196196
via polling or a push notification), call this function to trigger a
197197
reload.

src/express-http-server.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@ class ExpressHTTPServer {
1313
this.password = options.password;
1414
this.cache = options.cache;
1515
this.gzip = options.gzip || false;
16+
this.preFastbootMiddlewares = options.preFastbootMiddlewares || [];
17+
this.postFastbootMiddlewares = options.postFastbootMiddlewares || [];
1618

1719
this.app = express();
18-
if (options.gzip) {
19-
this.app.use(require('compression')());
20-
}
2120
}
2221

23-
serve(middleware) {
22+
serve(fastbootMiddleware) {
2423
let app = this.app;
2524
let username = this.username;
2625
let password = this.password;
2726

27+
this.preFastbootMiddlewares.forEach(args => app.use(...args));
28+
29+
if (this.gzip) {
30+
this.app.use(require('compression')());
31+
}
32+
2833
if (username !== undefined || password !== undefined) {
2934
this.ui.writeLine(`adding basic auth; username=${username}; password=${password}`);
3035
app.use(basicAuth(username, password));
@@ -35,14 +40,16 @@ class ExpressHTTPServer {
3540
}
3641

3742
if (this.distPath) {
38-
app.get('/', middleware);
43+
app.get('/', fastbootMiddleware);
3944
app.use(express.static(this.distPath));
4045
app.get('/assets/*', function(req, res) {
4146
res.sendStatus(404);
4247
});
4348
}
4449

45-
app.get('/*', middleware);
50+
app.get('/*', fastbootMiddleware);
51+
52+
this.postFastbootMiddlewares.forEach(args => app.use(...args));
4653

4754
return new Promise(resolve => {
4855
let listener = app.listen(process.env.PORT || 3000, () => {

src/fastboot-app-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class FastBootAppServer {
1515
this.notifier = options.notifier;
1616
this.cache = options.cache;
1717
this.ui = options.ui;
18-
this.gzip = options.gzip || false;
18+
this.gzip = options.gzip;
1919
this.httpServer = options.httpServer;
20+
this.preFastbootMiddlewares = options.preFastbootMiddlewares;
21+
this.postFastbootMiddlewares = options.postFastbootMiddlewares;
2022

2123
if (!this.ui) {
2224
let UI = require('./ui');

src/worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class Worker {
1010
this.httpServer = options.httpServer;
1111
this.ui = options.ui;
1212
this.cache = options.cache;
13-
this.gzip = options.gzip || false;
13+
this.gzip = options.gzip;
14+
this.preFastbootMiddlewares = options.preFastbootMiddlewares;
15+
this.postFastbootMiddlewares = options.postFastbootMiddlewares;
1416

1517
if (!this.httpServer) {
1618
this.httpServer = new ExpressHTTPServer({

0 commit comments

Comments
 (0)