From 57994ffb5bde08b4fa3a0914504eb56a66b5bc9f Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 1 May 2023 17:12:17 -0500 Subject: [PATCH] Only start ClientRouter for production --- index.js | 2 +- server/Server.js | 4 +++- server/routers/ClientRouter.js | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index ad1bc113e..f61ad36e5 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ global.appRoot = __dirname const isDev = process.env.NODE_ENV !== 'production' if (isDev) { const devEnv = require('./dev').config - process.env.NODE_ENV = 'development' + process.env.NODE_ENV = devEnv.Env || 'development' if (devEnv.Port) process.env.PORT = devEnv.Port if (devEnv.ConfigPath) process.env.CONFIG_PATH = devEnv.ConfigPath if (devEnv.MetadataPath) process.env.METADATA_PATH = devEnv.MetadataPath diff --git a/server/Server.js b/server/Server.js index 12ae1949d..076582520 100644 --- a/server/Server.js +++ b/server/Server.js @@ -139,7 +139,9 @@ class Server { async start() { Logger.info('=== Starting Server ===') await this.init() - this.clientRouter.start() + if (process.env.NODE_ENV !== 'development') { + this.clientRouter.start() + } const app = express() const router = express.Router() diff --git a/server/routers/ClientRouter.js b/server/routers/ClientRouter.js index a2a0b9178..89d4c1004 100644 --- a/server/routers/ClientRouter.js +++ b/server/routers/ClientRouter.js @@ -13,17 +13,18 @@ class ClientRouter { this.client = null this.router = express() this.router.disable('x-powered-by') - this.init() } - init () { + init() { const target = `http://localhost:${this.clientPort}${this.routerBasePath || '/'}` this.router.use(createProxyMiddleware({ target, changeOrigin: true })); Logger.info(`[Client] Proxying requests to client on port :${this.clientPort}`) } - start () { + start() { + this.init() + const clientDir = Path.join(this.appRoot, '/client') const clientPath = Path.join(clientDir, '/node_modules/@nuxt/cli/bin/nuxt-cli.js') this.client = childProcess.fork(clientPath, ["start"], { cwd: clientDir, stdio: 'pipe' }) @@ -44,7 +45,7 @@ class ClientRouter { }) } - stop () { + stop() { if (this.client) { this.client.off('exit') this.client.kill()