Skip to content

Commit bfdc01f

Browse files
committed
Add middleware options
1 parent 14c479b commit bfdc01f

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let server = new FastBootAppServer({
101101
});
102102

103103
server.start();
104-
```
104+
```
105105

106106
## Downloaders
107107

@@ -190,7 +190,7 @@ following interface:
190190

191191
#### `subscribe(notify)`
192192

193-
The `subscribe()` method ony our notifier is passed a `notify` function.
193+
The `subscribe()` method on your notifier is passed a `notify` function.
194194
If you detect that a new version of your app has been deployed (whether
195195
via polling or a push notification), call this function to trigger a
196196
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,11 +40,13 @@ class ExpressHTTPServer {
3540
}
3641

3742
if (this.distPath) {
38-
app.get('/', middleware);
43+
app.get('/', fastbootMiddleware);
3944
app.use(express.static(this.distPath));
4045
}
4146

42-
app.get('/*', middleware);
47+
app.get('/*', fastbootMiddleware);
48+
49+
this.postFastbootMiddlewares.forEach(args => app.use(...args));
4350

4451
return new Promise(resolve => {
4552
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)