diff --git a/Dockerfile b/Dockerfile index 0d4629f84d..4e110a6194 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,5 +46,10 @@ RUN apk del make python3 g++ EXPOSE 80 +ENV PORT=80 +ENV CONFIG_PATH="/config" +ENV METADATA_PATH="/metadata" +ENV SOURCE="docker" + ENTRYPOINT ["tini", "--"] CMD ["node", "index.js"] diff --git a/index.js b/index.js index 9a0be347cc..4b3a2648bd 100644 --- a/index.js +++ b/index.js @@ -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') global.appRoot = __dirname @@ -17,14 +32,19 @@ if (isDev) { process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath || '' } -const PORT = process.env.PORT || 80 -const HOST = process.env.HOST -const CONFIG_PATH = process.env.CONFIG_PATH || '/config' -const METADATA_PATH = process.env.METADATA_PATH || '/metadata' -const SOURCE = process.env.SOURCE || 'docker' +const inputConfig = options.config ? Path.resolve(options.config) : null +const 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('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) Server.start() diff --git a/package-lock.json b/package-lock.json index 31d9d0c261..6fd8cc2e96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,7 @@ "xml2js": "^0.5.0" }, "bin": { - "audiobookshelf": "prod.js" + "audiobookshelf": "index.js" }, "devDependencies": { "chai": "^4.3.10", diff --git a/package.json b/package.json index f6729ef6b8..ea73669c7d 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "description": "Self-hosted audiobook and podcast server", "main": "index.js", "scripts": { - "dev": "nodemon --watch server index.js", + "dev": "nodemon --watch server index.js -- --dev", "start": "node index.js", "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-linux": "build/linuxpackager", "docker": "docker buildx build --platform linux/amd64,linux/arm64 --push . -t advplyr/audiobookshelf", @@ -18,7 +18,7 @@ "test": "mocha", "coverage": "nyc mocha" }, - "bin": "prod.js", + "bin": "index.js", "pkg": { "assets": [ "client/dist/**/*", @@ -26,7 +26,7 @@ "server/migrations/*.js" ], "scripts": [ - "prod.js", + "index.js", "server/**/*.js" ] },