Merge prod.js into index.js

This commit is contained in:
mikiher 2025-01-07 17:41:09 +02:00
parent 0eed38b771
commit d410b13c9b
5 changed files with 36 additions and 44 deletions

View File

@ -46,5 +46,10 @@ RUN apk del make python3 g++
EXPOSE 80 EXPOSE 80
ENV PORT=80
ENV CONFIG_PATH="/config"
ENV METADATA_PATH="/metadata"
ENV SOURCE="docker"
ENTRYPOINT ["tini", "--"] ENTRYPOINT ["tini", "--"]
CMD ["node", "index.js"] CMD ["node", "index.js"]

View File

@ -1,3 +1,18 @@
const optionDefinitions = [
{ name: 'config', alias: 'c', type: String },
{ name: 'metadata', alias: 'm', type: String },
{ name: 'port', alias: 'p', type: String },
{ name: 'host', alias: 'h', type: String },
{ name: 'source', alias: 's', type: String },
{ name: 'dev', alias: 'd', type: Boolean }
]
const commandLineArgs = require('./server/libs/commandLineArgs')
const options = commandLineArgs(optionDefinitions)
const Path = require('path')
process.env.NODE_ENV = options.dev ? 'development' : process.env.NODE_ENV || 'production'
const server = require('./server/Server') const server = require('./server/Server')
global.appRoot = __dirname global.appRoot = __dirname
@ -17,14 +32,19 @@ if (isDev) {
process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath || '' process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath || ''
} }
const PORT = process.env.PORT || 80 const inputConfig = options.config ? Path.resolve(options.config) : null
const HOST = process.env.HOST const inputMetadata = options.metadata ? Path.resolve(options.metadata) : null
const CONFIG_PATH = process.env.CONFIG_PATH || '/config'
const METADATA_PATH = process.env.METADATA_PATH || '/metadata' const PORT = options.port || process.env.PORT || 3333
const SOURCE = process.env.SOURCE || 'docker' const HOST = options.host || process.env.HOST
const CONFIG_PATH = inputConfig || process.env.CONFIG_PATH || Path.resolve('config')
const METADATA_PATH = inputMetadata || process.env.METADATA_PATH || Path.resolve('metadata')
const SOURCE = options.source || process.env.SOURCE || 'debian'
const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || '' const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || ''
console.log('Config', CONFIG_PATH, METADATA_PATH) console.log(`Running in ${process.env.NODE_ENV} mode.`)
console.log(`Options: CONFIG_PATH=${CONFIG_PATH}, METADATA_PATH=${METADATA_PATH}, PORT=${PORT}, HOST=${HOST}, SOURCE=${SOURCE}, ROUTER_BASE_PATH=${ROUTER_BASE_PATH}`)
const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH) const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH)
Server.start() Server.start()

2
package-lock.json generated
View File

@ -30,7 +30,7 @@
"xml2js": "^0.5.0" "xml2js": "^0.5.0"
}, },
"bin": { "bin": {
"audiobookshelf": "prod.js" "audiobookshelf": "index.js"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.3.10", "chai": "^4.3.10",

View File

@ -5,10 +5,10 @@
"description": "Self-hosted audiobook and podcast server", "description": "Self-hosted audiobook and podcast server",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "nodemon --watch server index.js", "dev": "nodemon --watch server index.js -- --dev",
"start": "node index.js", "start": "node index.js",
"client": "cd client && npm ci && npm run generate", "client": "cd client && npm ci && npm run generate",
"prod": "npm run client && npm ci && node prod.js", "prod": "npm run client && npm ci && node index.js",
"build-win": "npm run client && pkg -t node20-win-x64 -o ./dist/win/audiobookshelf -C GZip .", "build-win": "npm run client && pkg -t node20-win-x64 -o ./dist/win/audiobookshelf -C GZip .",
"build-linux": "build/linuxpackager", "build-linux": "build/linuxpackager",
"docker": "docker buildx build --platform linux/amd64,linux/arm64 --push . -t advplyr/audiobookshelf", "docker": "docker buildx build --platform linux/amd64,linux/arm64 --push . -t advplyr/audiobookshelf",
@ -18,7 +18,7 @@
"test": "mocha", "test": "mocha",
"coverage": "nyc mocha" "coverage": "nyc mocha"
}, },
"bin": "prod.js", "bin": "index.js",
"pkg": { "pkg": {
"assets": [ "assets": [
"client/dist/**/*", "client/dist/**/*",
@ -26,7 +26,7 @@
"server/migrations/*.js" "server/migrations/*.js"
], ],
"scripts": [ "scripts": [
"prod.js", "index.js",
"server/**/*.js" "server/**/*.js"
] ]
}, },

33
prod.js
View File

@ -1,33 +0,0 @@
const optionDefinitions = [
{ name: 'config', alias: 'c', type: String },
{ name: 'metadata', alias: 'm', type: String },
{ name: 'port', alias: 'p', type: String },
{ name: 'host', alias: 'h', type: String },
{ name: 'source', alias: 's', type: String }
]
const commandLineArgs = require('./server/libs/commandLineArgs')
const options = commandLineArgs(optionDefinitions)
const Path = require('path')
process.env.NODE_ENV = 'production'
const server = require('./server/Server')
global.appRoot = __dirname
var inputConfig = options.config ? Path.resolve(options.config) : null
var inputMetadata = options.metadata ? Path.resolve(options.metadata) : null
const PORT = options.port || process.env.PORT || 3333
const HOST = options.host || process.env.HOST
const CONFIG_PATH = inputConfig || process.env.CONFIG_PATH || Path.resolve('config')
const METADATA_PATH = inputMetadata || process.env.METADATA_PATH || Path.resolve('metadata')
const SOURCE = options.source || process.env.SOURCE || 'debian'
const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || ''
console.log(process.env.NODE_ENV, 'Config', CONFIG_PATH, METADATA_PATH)
const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH)
Server.start()