Skip to content

Commit

Permalink
Update app server with workerPath
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Jun 2, 2021
1 parent ea740c3 commit 18706eb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
5 changes: 1 addition & 4 deletions packages/fastboot-app-server/src/fastboot-app-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class FastBootAppServer {
this.username = options.username;
this.password = options.password;
this.httpServer = options.httpServer;
this.beforeMiddleware = options.beforeMiddleware;
this.afterMiddleware = options.afterMiddleware;
this.buildSandboxGlobals = options.buildSandboxGlobals;
this.chunkedResponse = options.chunkedResponse;
this.workerPath = options.workerPath;

if (!this.ui) {
let UI = require('./ui');
Expand Down Expand Up @@ -229,8 +228,6 @@ class FastBootAppServer {
username: this.username,
password: this.password,
httpServer: this.httpServer,
beforeMiddleware: this.beforeMiddleware,
afterMiddleware: this.afterMiddleware,
buildSandboxGlobals: this.buildSandboxGlobals,
chunkedResponse: this.chunkedResponse,
};
Expand Down
1 change: 1 addition & 0 deletions packages/fastboot-app-server/src/worker-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This file is where you can configure
// - distPath, host, port,
// - httpServer
// - Middleware order
const ClusterWorker = require('./worker');
const worker = new ClusterWorker();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
var path = require('path');
const FastBootAppServer = require('../../src/fastboot-app-server');

function setXTestHeader(err, req, res, next) {
res.set('x-test-header', 'testing')
next();
}

var server = new FastBootAppServer({
distPath: path.resolve(__dirname, './broken-app'),
afterMiddleware: function (app) {
app.use(setXTestHeader);
},
workerPath: path.resolve(__dirname, './cluster-worker-start'),
resilient: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,9 @@
var path = require('path');
const FastBootAppServer = require('../../src/fastboot-app-server');

function setStatusCode418(req, res, next) {
res.status(418);
next();
}

function setXTestHeader(req, res, next) {
res.set('X-Test-Header', 'testing')
next();
}

function sendJsonAndTerminate(req, res, next) {
res.json({ send: 'json back' });
res.send();
}

var server = new FastBootAppServer({
distPath: path.resolve(__dirname, './basic-app'),
beforeMiddleware: function (app) {
app.use(setStatusCode418);
app.use(setXTestHeader);
app.use(sendJsonAndTerminate);
}
workerPath: path.resolve(__dirname, './cluster-worker-start'),
});

server.start();
37 changes: 37 additions & 0 deletions packages/fastboot-app-server/test/fixtures/cluster-worker-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const ClusterWorker = require('../../src/worker');

class CustomClusterWorker extends ClusterWorker {}

function setStatusCode418(req, res, next) {
res.status(418);
next();
}

function setXTestHeader(req, res, next) {
res.set('X-Test-Header', 'testing')
next();
}

function sendJsonAndTerminate(req, res, next) {
res.json({ send: 'json back' });
res.send();
}

function beforeMiddleware(app) {
app.use(setStatusCode418);
app.use(setXTestHeader);
app.use(sendJsonAndTerminate);
}

function afterMiddleware(app) {
app.use(setXTestHeader);
}

const worker = new CustomClusterWorker({
beforeMiddleware,
afterMiddleware,
});

worker.start();

0 comments on commit 18706eb

Please sign in to comment.