From 18706ebb70a3d359f47483d0a83749e2f132ed86 Mon Sep 17 00:00:00 2001 From: scott-newcomer Date: Wed, 2 Jun 2021 09:50:11 -0500 Subject: [PATCH] Update app server with workerPath --- .../src/fastboot-app-server.js | 5 +-- .../fastboot-app-server/src/worker-start.js | 1 + .../test/fixtures/after-middleware-server.js | 9 +---- .../test/fixtures/before-middleware-server.js | 21 +---------- .../test/fixtures/cluster-worker-start.js | 37 +++++++++++++++++++ 5 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 packages/fastboot-app-server/test/fixtures/cluster-worker-start.js diff --git a/packages/fastboot-app-server/src/fastboot-app-server.js b/packages/fastboot-app-server/src/fastboot-app-server.js index 81dc24f18..ca4e40281 100644 --- a/packages/fastboot-app-server/src/fastboot-app-server.js +++ b/packages/fastboot-app-server/src/fastboot-app-server.js @@ -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'); @@ -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, }; diff --git a/packages/fastboot-app-server/src/worker-start.js b/packages/fastboot-app-server/src/worker-start.js index 6b3eb10ec..cb4443988 100644 --- a/packages/fastboot-app-server/src/worker-start.js +++ b/packages/fastboot-app-server/src/worker-start.js @@ -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(); diff --git a/packages/fastboot-app-server/test/fixtures/after-middleware-server.js b/packages/fastboot-app-server/test/fixtures/after-middleware-server.js index 0a673e8da..526db6070 100644 --- a/packages/fastboot-app-server/test/fixtures/after-middleware-server.js +++ b/packages/fastboot-app-server/test/fixtures/after-middleware-server.js @@ -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, }); diff --git a/packages/fastboot-app-server/test/fixtures/before-middleware-server.js b/packages/fastboot-app-server/test/fixtures/before-middleware-server.js index 6de17305e..879785d31 100644 --- a/packages/fastboot-app-server/test/fixtures/before-middleware-server.js +++ b/packages/fastboot-app-server/test/fixtures/before-middleware-server.js @@ -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(); diff --git a/packages/fastboot-app-server/test/fixtures/cluster-worker-start.js b/packages/fastboot-app-server/test/fixtures/cluster-worker-start.js new file mode 100644 index 000000000..c60bd70bb --- /dev/null +++ b/packages/fastboot-app-server/test/fixtures/cluster-worker-start.js @@ -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();