Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATABASE_URL=
REDIS_URL=

CSH_CLIENT_ID=
CSH_CLIENT_SECRET=
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/views/HomeView.vue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change seems unrelated to the rest of the PR.

Also what does it do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There was some weirdness that I think is my fault, I explained in slack

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default defineComponent({

.noOverflow > * {
overflow: auto;
white-space: nowrap;
text-overflow: ellipsis;
}

Expand Down
31 changes: 21 additions & 10 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
Expand All @@ -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())
Expand Down
Loading