made backend database url configurable through cli
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -257,7 +257,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "chatapp"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argon2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "chatapp"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
in {
|
||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "chatapp";
|
||||
version = "0.1.0";
|
||||
version = "0.2.0";
|
||||
|
||||
# Point to the backend subdirectory
|
||||
src = ./backend;
|
||||
|
||||
@@ -2,9 +2,9 @@ use axum::http::StatusCode;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn init_db() -> Result<PgPool, sqlx::Error> {
|
||||
let database_url = "postgres://chatapp:secret@localhost:5432/chatapp";
|
||||
PgPool::connect(database_url).await
|
||||
pub async fn init_db(url: String) -> Result<PgPool, sqlx::Error> {
|
||||
let database_url = format!("postgres://chatapp:secret@{url}/chatapp");
|
||||
PgPool::connect(database_url.as_str()).await
|
||||
}
|
||||
|
||||
pub async fn user_id_from_uuid(db: &PgPool, user_uuid: Uuid) -> Result<i32, (StatusCode, String)> {
|
||||
|
||||
@@ -29,6 +29,10 @@ pub struct Cli {
|
||||
#[arg(short, long, default_value = "8080")]
|
||||
port: String,
|
||||
|
||||
/// Database URL
|
||||
#[arg(short, long, default_value = "localhost:5432")]
|
||||
database: String,
|
||||
|
||||
/// Verbose mode
|
||||
#[arg(short, long)]
|
||||
verbose: bool,
|
||||
@@ -43,7 +47,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
.init();
|
||||
|
||||
tracing::info!("Connecting to database...");
|
||||
let db_pool = db::init_db().await?;
|
||||
let db_pool = db::init_db(cli.database).await?;
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
|
||||
Reference in New Issue
Block a user