Skip to content

Commit

Permalink
Support set DATABASE_URL when create project (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
sansx authored Mar 29, 2024
1 parent c7b7652 commit 3d08fef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 12 additions & 1 deletion create-rust-app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ fn create_project(
}
};

println!("Press Enter will use default backend database url as config");

let backend_database_url: String = Input::new()
.with_prompt(format!("{:?} url", backend_database))
.default("postgres://postgres:postgres@localhost/database".into())
.show_default(false)
.interact_text()?;

// get the backend framework
let backend_framework: BackendFramework = match framework {
Some(framework) => framework,
Expand Down Expand Up @@ -474,7 +482,10 @@ fn create_project(

let contents = std::fs::read_to_string(example_env_file)
.expect("Error: Tried to read .env.example contents but an error occurred");
std::fs::write(env_file, contents)?;
std::fs::write(
env_file,
format!("{}DATABASE_URL={}", contents, backend_database_url),
)?;
logger::add_file_msg(".env");

logger::project_created_msg(install_config);
Expand Down
1 change: 0 additions & 1 deletion create-rust-app_cli/template/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
RUST_LOG=debug
SECRET_KEY=secret
DATABASE_URL=postgres://postgres:postgres@localhost/database
RUST_BACKTRACE=1
APP_URL=http://localhost:3000

0 comments on commit 3d08fef

Please sign in to comment.