Skip to content

Commit 6aa1481

Browse files
author
Robert Jackson
committed
Merge branch 'allow-server-customizations'
Closes #12
2 parents e5f57f3 + 178ac59 commit 6aa1481

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ The app server will automatically spawn a new worker if one dies while
7171
handling a request. When a new application deploy is detected, workers
7272
will automatically reload with the newest version.
7373

74+
## Custom HTTP Server
75+
You can customize HTTP server (add middlewares, subdomains, etc.), either directly:
76+
```js
77+
// start.js
78+
const httpServer = new ExpressHTTPServer(/* {options} */);
79+
const app = httpServer.app;
80+
app.use('/api', apiRoutes);
81+
let server = new FastBootAppServer({
82+
httpServer: httpServer
83+
});
84+
85+
server.start();
86+
```
87+
or extend the provided HTTP server and override any methods you need:
88+
```js
89+
// my-custom-express-server.js
90+
const ExpressHTTPServer = require('fastboot-app-server/lib/express-http-server');
91+
class MyCustomExpressServer extends ExpressHTTPServer {
92+
serve(middleware) {
93+
// put your custom code here, don't forget to add fastboot etc.
94+
}
95+
}
96+
// start.js
97+
const MyCustomExpressServer = require('./my-custom-express-server');
98+
const httpServer = new MyCustomExpressServer(/* {options} */);
99+
let server = new FastBootAppServer({
100+
httpServer: httpServer
101+
});
102+
103+
server.start();
104+
```
105+
74106
## Downloaders
75107

76108
You can point the app server at a static path that you manage, but that

src/fastboot-app-server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class FastBootAppServer {
1616
this.cache = options.cache;
1717
this.ui = options.ui;
1818
this.gzip = options.gzip || false;
19-
19+
this.httpServer = options.httpServer;
20+
2021
if (!this.ui) {
2122
let UI = require('./ui');
2223
this.ui = new UI();
@@ -30,6 +31,7 @@ class FastBootAppServer {
3031
distPath: this.distPath || process.env.FASTBOOT_DIST_PATH,
3132
cache: this.cache,
3233
gzip: this.gzip
34+
httpServer: this.httpServer,
3335
});
3436

3537
this.worker.start();
@@ -67,6 +69,7 @@ class FastBootAppServer {
6769
if (this.downloader) { this.downloader.ui = this.ui; }
6870
if (this.notifier) { this.notifier.ui = this.ui; }
6971
if (this.cache) { this.cache.ui = this.ui; }
72+
if (this.httpServer) { this.httpServer.ui = this.ui; }
7073
}
7174

7275
initializeApp() {

src/worker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class Worker {
1919
cache: this.cache
2020
});
2121
}
22+
23+
if (!this.httpServer.cache) { this.httpServer.cache = this.cache; }
24+
if (!this.httpServer.distPath) { this.httpServer.distPath = this.distPath; }
25+
if (!this.httpServer.ui) { this.httpServer.ui = this.ui; }
2226
}
2327

2428
start() {

0 commit comments

Comments
 (0)