diff --git a/.env.example b/.env.example index 99771b8..6fd6d84 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ DATABASE_URL= +REDIS_URL= CSH_CLIENT_ID= CSH_CLIENT_SECRET= diff --git a/README.md b/README.md index 9b2ea59..7d40fc2 100644 --- a/README.md +++ b/README.md @@ -29,18 +29,22 @@ A Proper Rideboard. 1. Copy `.env.example` as `.env` 2. Fill in data fields. - - For `DATABASE_URL`, format is `postgresql://USERNAME:PASSWORD@HOST/DATABASE` - - Contact an RTP for CSH Auth Credentials. - - Create a local set of keys for the Google Auth. See [this guide](https://developers.google.com/identity/sign-in/web/sign-in) for guidance. + - For `DATABASE_URL`, format is `postgresql://USERNAME:PASSWORD@HOST/DATABASE`, example for just running the docker compose: `postgresql://rideboard:supersecurepassword@localhost:5432/rideboard` + - Contact an RTP for CSH Auth Credentials for these fields: `CSH_CLIENT_ID`, `CSH_CLIENT_SECRET`, `CSH_AUTH_URL`, `CSH_TOKEN_URL`, `CSH_USERINFO_URL`. + - Create a local set of keys for the Google Auth, fill out GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. See [this guide](https://developers.google.com/identity/sign-in/web/sign-in) for guidance. - `REDIRECT_DOMAIN` is the full protocol and domain for your project. Ex `http://localhost:8080`, `https://rideboard-v2.cs.house`. + - `HOST` is the host for your project. Ex `localhost`, `rideboard-v2.cs.house`. + - `PORT` is the port for your project. Ex `8080`. -#### Running Program +#### Running the Project -1. Build Frontend. `cd src/frontend; npm run build` +1. Run postgres and redis with docker-compose. `docker compose up -d` -2. Build server binary. `cargo build` +2. Install frontend dependencies. `cd src/frontend; npm install` -3. Run! `./target/debug/rideboard-v2` +2. Build Frontend. `npm run build` or `npm run dev` for development. + +3. Build and run the server binary. `cargo run server` ### Frontend Development Tip diff --git a/src/frontend/src/views/HomeView.vue b/src/frontend/src/views/HomeView.vue index f7c33a5..97c868b 100644 --- a/src/frontend/src/views/HomeView.vue +++ b/src/frontend/src/views/HomeView.vue @@ -112,7 +112,6 @@ export default defineComponent({ .noOverflow > * { overflow: auto; - white-space: nowrap; text-overflow: ellipsis; } diff --git a/src/server.rs b/src/server.rs index 4ad5e2f..209a0a1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -41,18 +41,26 @@ async fn serve_index() -> impl Responder { } } +fn require_env_var(name: &str) -> String { + let value = env::var(name).unwrap_or_else(|_| panic!("{name} must be set")); + assert!( + !value.trim().is_empty(), + "{name} environmental variable cannot be empty/missing" + ); + value +} + pub async fn main() -> Result<()> { - let host = env::var("HOST").unwrap_or("127.0.0.1".to_string()); + let host = require_env_var("HOST"); let host_inner = host.clone(); - let port: i32 = match &env::var("PORT").map(|port| port.parse()) { - Ok(Ok(p)) => *p, - Ok(Err(_)) => 8080, - Err(_) => 8080, - }; + let port: i32 = require_env_var("PORT") + .parse() + .expect("PORT must be a valid integer"); + let database_url = require_env_var("DATABASE_URL"); let db_pool = PgPoolOptions::new() .max_connections(5) - .connect(&env::var("DATABASE_URL").expect("DATABASE_URL must be set")) + .connect(&database_url) .await .expect("Failed to create pool"); @@ -66,12 +74,16 @@ pub async fn main() -> Result<()> { .map(|key| Key::from(&key)) .unwrap_or(Key::generate()); - let redis_conn = redis::Client::open(env::var("REDIS_URL").expect("REDIS_URL must be set")) + let redis_url = require_env_var("REDIS_URL"); + + let redis_conn = redis::Client::open(redis_url.clone()) .expect("Failed to create Redis Client") .get_multiplexed_async_connection() .await .expect("Failed to create Redis Connection"); + let csh_userinfo_url = require_env_var("CSH_USERINFO_URL"); + info!("Starting server at http://{host}:{port}"); HttpServer::new(move || { let (google_client, csh_client) = auth::get_clients(&host_inner, port); @@ -86,8 +98,7 @@ pub async fn main() -> Result<()> { google_oauth: google_client, google_userinfo_url: "https://openidconnect.googleapis.com/v1/userinfo".to_string(), csh_oauth: csh_client, - csh_userinfo_url: env::var("CSH_USERINFO_URL") - .expect("Missing Userinfo URL for CSH Auth"), + csh_userinfo_url: csh_userinfo_url.clone(), })) .wrap( SessionMiddleware::builder(CookieSessionStore::default(), session_key.clone())