Skip to content

Commit

Permalink
Merge pull request #3808 from mikiher/merge-prod-js-index-js
Browse files Browse the repository at this point in the history
Merge prod.js into index.js
  • Loading branch information
advplyr authored Jan 8, 2025
2 parents 5edd799 + 052e005 commit 1649fb4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
32 changes: 26 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -18,15 +18,15 @@
"test": "mocha",
"coverage": "nyc mocha"
},
"bin": "prod.js",
"bin": "index.js",
"pkg": {
"assets": [
"client/dist/**/*",
"node_modules/sqlite3/lib/binding/**/*.node",
"server/migrations/*.js"
],
"scripts": [
"prod.js",
"index.js",
"server/**/*.js"
]
},
Expand Down

0 comments on commit 1649fb4

Please sign in to comment.