Skip to content

Commit ecdac68

Browse files
author
Arjan Singh
committed
pre-FastBoot and post-FastBoot middleware hooks
1 parent bfdc01f commit ecdac68

File tree

11 files changed

+84187
-3
lines changed

11 files changed

+84187
-3
lines changed

src/fastboot-app-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class FastBootAppServer {
3333
distPath: this.distPath || process.env.FASTBOOT_DIST_PATH,
3434
cache: this.cache,
3535
gzip: this.gzip,
36-
httpServer: this.httpServer
36+
httpServer: this.httpServer,
37+
preFastbootMiddlewares: this.preFastbootMiddlewares,
38+
postFastbootMiddlewares: this.postFastbootMiddlewares
3739
});
3840

3941
this.worker.start();

src/worker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Worker {
1919
ui: this.ui,
2020
distPath: this.distPath,
2121
cache: this.cache,
22-
gzip: this.gzip
22+
gzip: this.gzip,
23+
preFastbootMiddlewares: this.preFastbootMiddlewares,
24+
postFastbootMiddlewares: this.postFastbootMiddlewares,
2325
});
2426
}
2527

@@ -60,7 +62,6 @@ class Worker {
6062
buildMiddleware() {
6163
this.fastboot = new FastBoot({
6264
distPath: this.distPath,
63-
resilient: true
6465
});
6566

6667
return fastbootMiddleware({

test/app-server-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ describe("FastBootAppServer", function() {
5656
});
5757
});
5858

59+
it("executes preFastbootMiddlewares", function() {
60+
return runServer('prefastboot-middleware-server')
61+
.then(() => request('http://localhost:3000'))
62+
.then(response => {
63+
expect(response.statusCode).to.equal(418);
64+
expect(response.headers['x-test-header']).to.equal('testing');
65+
expect(response.body).to.equal(JSON.stringify({ send: 'json back'}));
66+
});
67+
});
68+
69+
it("executes postFastbootMiddlewares when there is an error", function() {
70+
return runServer('postfastboot-middleware-server')
71+
.then(() => request('http://localhost:3000'))
72+
.then(response => {
73+
expect(response.body).to.not.match(/error/);
74+
expect(response.headers['x-test-header']).to.equal('testing');
75+
})
76+
});
77+
5978
});
6079

6180
function runServer(name) {

0 commit comments

Comments
 (0)