Skip to content

Commit 18706eb

Browse files
committed
Update app server with workerPath
1 parent ea740c3 commit 18706eb

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

packages/fastboot-app-server/src/fastboot-app-server.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ class FastBootAppServer {
2121
this.username = options.username;
2222
this.password = options.password;
2323
this.httpServer = options.httpServer;
24-
this.beforeMiddleware = options.beforeMiddleware;
25-
this.afterMiddleware = options.afterMiddleware;
2624
this.buildSandboxGlobals = options.buildSandboxGlobals;
2725
this.chunkedResponse = options.chunkedResponse;
26+
this.workerPath = options.workerPath;
2827

2928
if (!this.ui) {
3029
let UI = require('./ui');
@@ -229,8 +228,6 @@ class FastBootAppServer {
229228
username: this.username,
230229
password: this.password,
231230
httpServer: this.httpServer,
232-
beforeMiddleware: this.beforeMiddleware,
233-
afterMiddleware: this.afterMiddleware,
234231
buildSandboxGlobals: this.buildSandboxGlobals,
235232
chunkedResponse: this.chunkedResponse,
236233
};

packages/fastboot-app-server/src/worker-start.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is where you can configure
44
// - distPath, host, port,
55
// - httpServer
6+
// - Middleware order
67
const ClusterWorker = require('./worker');
78
const worker = new ClusterWorker();
89

packages/fastboot-app-server/test/fixtures/after-middleware-server.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
var path = require('path');
44
const FastBootAppServer = require('../../src/fastboot-app-server');
55

6-
function setXTestHeader(err, req, res, next) {
7-
res.set('x-test-header', 'testing')
8-
next();
9-
}
10-
116
var server = new FastBootAppServer({
127
distPath: path.resolve(__dirname, './broken-app'),
13-
afterMiddleware: function (app) {
14-
app.use(setXTestHeader);
15-
},
8+
workerPath: path.resolve(__dirname, './cluster-worker-start'),
169
resilient: true,
1710
});
1811

packages/fastboot-app-server/test/fixtures/before-middleware-server.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,9 @@
33
var path = require('path');
44
const FastBootAppServer = require('../../src/fastboot-app-server');
55

6-
function setStatusCode418(req, res, next) {
7-
res.status(418);
8-
next();
9-
}
10-
11-
function setXTestHeader(req, res, next) {
12-
res.set('X-Test-Header', 'testing')
13-
next();
14-
}
15-
16-
function sendJsonAndTerminate(req, res, next) {
17-
res.json({ send: 'json back' });
18-
res.send();
19-
}
20-
216
var server = new FastBootAppServer({
227
distPath: path.resolve(__dirname, './basic-app'),
23-
beforeMiddleware: function (app) {
24-
app.use(setStatusCode418);
25-
app.use(setXTestHeader);
26-
app.use(sendJsonAndTerminate);
27-
}
8+
workerPath: path.resolve(__dirname, './cluster-worker-start'),
289
});
2910

3011
server.start();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const ClusterWorker = require('../../src/worker');
4+
5+
class CustomClusterWorker extends ClusterWorker {}
6+
7+
function setStatusCode418(req, res, next) {
8+
res.status(418);
9+
next();
10+
}
11+
12+
function setXTestHeader(req, res, next) {
13+
res.set('X-Test-Header', 'testing')
14+
next();
15+
}
16+
17+
function sendJsonAndTerminate(req, res, next) {
18+
res.json({ send: 'json back' });
19+
res.send();
20+
}
21+
22+
function beforeMiddleware(app) {
23+
app.use(setStatusCode418);
24+
app.use(setXTestHeader);
25+
app.use(sendJsonAndTerminate);
26+
}
27+
28+
function afterMiddleware(app) {
29+
app.use(setXTestHeader);
30+
}
31+
32+
const worker = new CustomClusterWorker({
33+
beforeMiddleware,
34+
afterMiddleware,
35+
});
36+
37+
worker.start();

0 commit comments

Comments
 (0)