From 4c43806419d441ffd7f870ce5357081577c1ad72 Mon Sep 17 00:00:00 2001 From: Nettika Date: Sun, 25 Jan 2026 15:38:14 -0800 Subject: [PATCH] Support dotenv files --- .env.example | 6 ++++++ .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 1 + TODO.md | 2 +- src/main.rs | 3 +++ 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..fb4dc72 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Example environment variables for makeprogress +# Copy this file to .env and update with your values + +# Authentication credentials +USERNAME=admin +PASSWORD=changeme diff --git a/.gitignore b/.gitignore index b82c298..bb67038 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target projects.db +.env diff --git a/Cargo.lock b/Cargo.lock index 83aea59..1e2cdf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,12 @@ dependencies = [ "syn", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "errno" version = "0.3.14" @@ -497,6 +503,7 @@ checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" name = "makeprogress" version = "0.1.0" dependencies = [ + "dotenvy", "maud", "rouille", "rusqlite", diff --git a/Cargo.toml b/Cargo.toml index 4487223..6b796bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" rouille = "3.6" rusqlite = { version = "0.32", features = ["bundled"] } maud = "0.26" +dotenvy = "0.15" diff --git a/TODO.md b/TODO.md index e2751d5..f45599e 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ [x] Create a `GET /projects` endpoint. Using Maud for markup generation, have this endpoint return an HTML page that shows all projects. Each project should be a `project-card` web component. Keep the page simple: no title or any buttons currently. [x] Create a `POST /projects` endpoint that accepts URL encoded data and creates a new project. [x] Create a `GET /new-project` endpoint that returns a HTML page with a project creation form. Keep it simple. -[ ] Add .env file support using the dotenv crate. Load environment variables on server startup. +[x] Add .env file support using the dotenv crate. Load environment variables on server startup. [ ] Create a `GET /login` endpoint that returns a simple HTML login form (username and password fields). [ ] Create a `POST /login` endpoint that validates credentials against USERNAME and PASSWORD environment variables. On success, set a session cookie. [ ] Implement session management. Create a simple in-memory session store that tracks authenticated sessions by cookie token. diff --git a/src/main.rs b/src/main.rs index 5bbc2ed..f9ac956 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,9 @@ mod project; const STALE_AGE: i64 = 30 * 24 * 60 * 60; // 30 days in seconds fn main() { + // Load environment variables from .env file if it exists + dotenvy::dotenv().ok(); + println!("Starting server on localhost:8080"); rouille::start_server("localhost:8080", move |request| {