Only start ClientRouter for production

This commit is contained in:
advplyr 2023-05-01 17:12:17 -05:00
parent 634167aea6
commit 57994ffb5b
3 changed files with 9 additions and 6 deletions

View file

@ -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

View file

@ -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()

View file

@ -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()