mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-15 22:01:37 +00:00
Only start ClientRouter for production
This commit is contained in:
parent
634167aea6
commit
57994ffb5b
3 changed files with 9 additions and 6 deletions
2
index.js
2
index.js
|
|
@ -4,7 +4,7 @@ global.appRoot = __dirname
|
||||||
const isDev = process.env.NODE_ENV !== 'production'
|
const isDev = process.env.NODE_ENV !== 'production'
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
const devEnv = require('./dev').config
|
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.Port) process.env.PORT = devEnv.Port
|
||||||
if (devEnv.ConfigPath) process.env.CONFIG_PATH = devEnv.ConfigPath
|
if (devEnv.ConfigPath) process.env.CONFIG_PATH = devEnv.ConfigPath
|
||||||
if (devEnv.MetadataPath) process.env.METADATA_PATH = devEnv.MetadataPath
|
if (devEnv.MetadataPath) process.env.METADATA_PATH = devEnv.MetadataPath
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,9 @@ class Server {
|
||||||
async start() {
|
async start() {
|
||||||
Logger.info('=== Starting Server ===')
|
Logger.info('=== Starting Server ===')
|
||||||
await this.init()
|
await this.init()
|
||||||
this.clientRouter.start()
|
if (process.env.NODE_ENV !== 'development') {
|
||||||
|
this.clientRouter.start()
|
||||||
|
}
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,18 @@ class ClientRouter {
|
||||||
this.client = null
|
this.client = null
|
||||||
this.router = express()
|
this.router = express()
|
||||||
this.router.disable('x-powered-by')
|
this.router.disable('x-powered-by')
|
||||||
this.init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init () {
|
init() {
|
||||||
const target = `http://localhost:${this.clientPort}${this.routerBasePath || '/'}`
|
const target = `http://localhost:${this.clientPort}${this.routerBasePath || '/'}`
|
||||||
this.router.use(createProxyMiddleware({ target, changeOrigin: true }));
|
this.router.use(createProxyMiddleware({ target, changeOrigin: true }));
|
||||||
|
|
||||||
Logger.info(`[Client] Proxying requests to client on port :${this.clientPort}`)
|
Logger.info(`[Client] Proxying requests to client on port :${this.clientPort}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
start () {
|
start() {
|
||||||
|
this.init()
|
||||||
|
|
||||||
const clientDir = Path.join(this.appRoot, '/client')
|
const clientDir = Path.join(this.appRoot, '/client')
|
||||||
const clientPath = Path.join(clientDir, '/node_modules/@nuxt/cli/bin/nuxt-cli.js')
|
const clientPath = Path.join(clientDir, '/node_modules/@nuxt/cli/bin/nuxt-cli.js')
|
||||||
this.client = childProcess.fork(clientPath, ["start"], { cwd: clientDir, stdio: 'pipe' })
|
this.client = childProcess.fork(clientPath, ["start"], { cwd: clientDir, stdio: 'pipe' })
|
||||||
|
|
@ -44,7 +45,7 @@ class ClientRouter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop() {
|
||||||
if (this.client) {
|
if (this.client) {
|
||||||
this.client.off('exit')
|
this.client.off('exit')
|
||||||
this.client.kill()
|
this.client.kill()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue