Skip to content

Conversation

@botagas
Copy link

@botagas botagas commented Mar 28, 2025

What needs to be done

  • Define PORT and LISTEN_IP in environment variables for later use
  • Use process.env.<var> to grab PORT and LISTEN_IP vars from .env

What has been done

  • Added PORT and LISTEN_IP in .env.example file
  • Added variables to README
  • Added process.env.PORT and process.env.LISTEN_IP instead of hardcoded values. If the variables are not set, we use defaults.

Greatly helps with automation situations on bare metal, since otherwise you need to edit the file manually (or automate the manual editing process) in order to have the service listen on a different port/ip. An option is to use a reverse proxy to work around it, but that doesn't solve the main concern here.

Please do verify changes, I am no professional in terms of coding and programming, I just package apps and edit code from time to time.

Suggestions for further improvement that I would like to implement

  • Implement ability to not fail if database is already created. Instead, either re-create db or use existing if valid. For instance, instead of using await client.query(`CREATE DATABASE ' \\+ _POSTGRES_DATABASE`);, we could use something like SELECT 'CREATE DATABASE <db>' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '<db>'). This is just an idea if anyone proceeds with this.
  • Implement ability to pre-create user and predefine Jellyfin values. As it is now, automating is difficult because instead of defining this in .env file, you have to proceed with the following curl requests to hack the process:
# Create admin user
API_TOKEN_RESPONSE=$(curl --silent --show-error --fail -X POST http://127.0.0.1:$port/auth/createuser -H "Content-Type: application/json" -d '{"username": "'"$js_user"'", "password": "'"$js_password"'"}')
API_TOKEN=$(echo "$API_TOKEN_RESPONSE" | jq -r '.token')

# Create and save API_KEY
API_KEY_RESPONSE=$(curl --silent --show-error --fail -X POST http://127.0.0.1:$port/api/keys -H "Content-Type: application/json" -H "Authorization: Bearer $API_TOKEN" -d '{"name": "$name"}')
API_KEY=$(echo "$API_KEY_RESPONSE" | jq -r '.[-1].key')

##############################################################
# some further steps for the Jellyfin fields might be required
##############################################################

# Verify if setup stage has incremented
setup_state_response=$(curl --silent --show-error --fail -X GET http://127.0.0.1:$port/auth/isConfigured -H "Content-Type: application/json")

@botagas botagas changed the base branch from main to unstable March 28, 2025 01:39
@botagas
Copy link
Author

botagas commented Mar 28, 2025

Didn't realize the JS_LISTEN_IP idea was already being thought of in unstable, so I've altered the changes I had to reflect what was being done in unstable as well.

@CyferShepard
Copy link
Owner

Hey @botagas , just completed testing on this change and realized that when the port is changed. In the compiled build of the ui, the backend is unreachable due to the proxy mapping being baked in during the docker image compilation. This is defined in vite.config.js and im not too sure how this can be changed to dynamically reference the new port whenever its updated in the ENV, A good starting place would be to check how the base url is being updated via the env.js build file on the server side that creates a new .env.js file at startup based on the values passed to it from docker.

@botagas
Copy link
Author

botagas commented Apr 2, 2025

Hey @botagas , just completed testing on this change and realized that when the port is changed. In the compiled build of the ui, the backend is unreachable due to the proxy mapping being baked in during the docker image compilation. This is defined in vite.config.js and im not too sure how this can be changed to dynamically reference the new port whenever its updated in the ENV, A good starting place would be to check how the base url is being updated via the env.js build file on the server side that creates a new .env.js file at startup based on the values passed to it from docker.

I will look into this a bit more after I am more inline with finishing my master's thesis, deadlines are catching up to me. I will try my best to revisit this again. I looked into what you mentioned a few days ago and I think I had an idea or two but didn't have enough time to tinker with it.

EDIT: I will be revisiting this after a week or so, at the start of the next month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants