Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the use of .env for setting runtime variables and non-static setting of CORS allow_origins #86

Merged
merged 6 commits into from
Dec 14, 2024

Conversation

jhodapp
Copy link
Member

@jhodapp jhodapp commented Dec 12, 2024

Description

This PR enables the use of .env for setting runtime variables alongside CLI params. Also accept a list of CORS allowed origin URLs instead of hardcoding them.

GitHub Issue: None

Changes

  • Enable the use of a .env file at runtime for setting all of the command line flags
  • Allow the setting of a list of servers to allow for CORS Allow Origins purposes

Testing Strategy

  1. Test using the following .env file when running the backend as bare metal or when building the Docker containers
# PostgreSQL environment variables for local development
POSTGRES_USER=refactor  # Default PostgreSQL user for local development
POSTGRES_PASSWORD=password  # Default PostgreSQL password for local development
POSTGRES_DB=refactor  # Default PostgreSQL database for local development
POSTGRES_HOST=postgres  # The local Docker Compose PostgreSQL container hostname
POSTGRES_PORT=5432  # PostgreSQL default port for local development
POSTGRES_SCHEMA=refactor_platform  # PostgreSQL schema for the application
# Database connection URL for the Rust application
# Rust application environment variables
ALLOWED_ORIGINS="http://localhost:3000,http://localhost:3001,http://*.rove-barbel.ts.net:3000,https://jims-macbook-air.rove-barbel.ts.net,https://jims-macbook-air.rove-barbel.ts.net:3000,http://jims-macbook-air.rove-barbel.ts.net:3000,http://100.66.34.44:3000,http://192.168.1.65:3000,http://192.168.1.111:3000"
DATABASE_URI=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
INTERFACE="0.0.0.0"
LOG_LEVEL_FILTER="DEBUG"
PORT=4000

NEXTJS_FRONTEND_PORT=3000

CONTAINER_NAME="refactor-platform"

# App user configuration
USERNAME=appuser  # Username for the non-root user in the container
USER_UID=1000  # User ID for the appuser
USER_GID=1000  # Group ID for the appuser

Concerns

None

…rams. Also accept a list of CORS allowed origin URLs instead of hardcoding them.
@jhodapp jhodapp added the enhancement Improves existing functionality or feature label Dec 12, 2024
@jhodapp jhodapp added this to the 1.0-rc1 milestone Dec 12, 2024
@jhodapp jhodapp self-assigned this Dec 12, 2024
Copy link
Collaborator

@calebbourg calebbourg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thank you for adding this.
Just a question and a request:

Q: Does this mean we will not have to specify a .env file when running the app with docker-compose? If so will it correctly distinguish between something like .env and .env.local?

R: Could you provide a new example .env file in the docs that uses the new variable names?

web/src/lib.rs Outdated
@@ -22,6 +25,7 @@ pub(crate) mod extractors;
mod router;

pub async fn init_server(app_state: AppState) -> Result<()> {
info!("Connecting to DB with URI: {}", app_state.config.database_uri());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would make sense to change this to debug! so we don't log the URI in production? Thinking more of down the line if we are using like an AWS database. Not really sure if the URI itself would contain any sensitive information but just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question, I actually had it as debug originally but I messed up the order in my mind. I'm going to switch this to TRACE so that it only shows up when we really want it to. And at some point we may even decide that this is not even necessary.

@jhodapp
Copy link
Member Author

jhodapp commented Dec 13, 2024

This looks great! Thank you for adding this. Just a question and a request:

Q: Does this mean we will not have to specify a .env file when running the app with docker-compose? If so will it correctly distinguish between something like .env and .env.local?

It appears that by default, dotenvy only loads a .env, but it does have a function if we want to provide a way to load from something custom-named like .env-local.

R: Could you provide a new example .env file in the docs that uses the new variable names?

Happy to.

@jhodapp jhodapp merged commit 1808420 into main Dec 14, 2024
4 checks passed
@jhodapp jhodapp deleted the tweak_cors_policy_for_dev_and_prod branch December 14, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves existing functionality or feature
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants