Allow setting UI and API ports via env var - #7
Conversation
|
On my machine, running with rootless docker the default values (not copying .env.sample to .env) results in the following output: |
|
Running on this branch with the following values for my .env file results in the following: Abridged output from yew-ui (last few lines): Abridged output from actix-api (last few lines): |
|
@darioalessandro let me know if you'd like the Postgres port parametrized as well. Wasn't as big a priority for me because it wasn't running on a privileged port, but might as well since I did the actix API port and that wasn't running on anything privileged either. |
| const ACTIX_PORT: &str = std::env!("ACTIX_PORT"); | ||
| const UI_PORT: &str = std::env!("TRUNK_SERVE_PORT"); | ||
| const UI_HOST: &str = std::env!("TRUNK_SERVE_HOST"); | ||
| const AFTER_LOGIN_URL: &'static str = concat!("http://localhost:", std::env!("TRUNK_SERVE_PORT")); |
There was a problem hiding this comment.
I felt kinda iffy about this line (specifically having to repeat the same std::env expression on lines 29 and 31), but it was the most concise-looking way I found to append TRUNK_SERVE_PORT to a string slice after a brief bit of googling. Let me know if there's a better way or if you prefer the accepted answer from that stack overflow post, I'm still very much a Rust newbie.
| - ACTIX_PORT=8080 | ||
| - TRUNK_SERVE_PORT=80 | ||
| - ACTIX_PORT=${ACTIX_PORT:-8080} | ||
| - TRUNK_SERVE_PORT=${TRUNK_SERVE_PORT:-80} |
There was a problem hiding this comment.
@resnickmicah this is awesome!!
I did not know you could provide defaults like this!!!
| - LOGIN_URL=http://localhost:${ACTIX_PORT:-8080}/login | ||
| ports: | ||
| - "80:80" | ||
| - "${TRUNK_SERVE_PORT:-80}:${TRUNK_SERVE_PORT:-80}" |
| - PG_URL=postgres://postgres:docker@postgres:5432/actix-api-db?sslmode=disable | ||
| ports: | ||
| - "8080:8080" | ||
| - "${ACTIX_PORT:-8080}:${ACTIX_PORT:-8080}" |
| const ACTIX_PORT: &str = std::env!("ACTIX_PORT"); | ||
| const UI_PORT: &str = std::env!("TRUNK_SERVE_PORT"); | ||
| const UI_HOST: &str = std::env!("TRUNK_SERVE_HOST"); | ||
| const AFTER_LOGIN_URL: &'static str = concat!("http://localhost:", std::env!("TRUNK_SERVE_PORT")); |
Make sure the UI and API respect any values set for
ACTIX_PORTandTRUNK_SERVE_PORT. Have these values default to ACTIX_PORT=8080 and TRUNK_SERVE_PORT=80 in the absence of any .env file.