diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b3137af0..a104d861 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Deploy React App to GitHub Pages on: push: branches: - - main # deploy when main branch is pushed + - prod # deploy when prod branch is pushed jobs: build-and-deploy: diff --git a/README.md b/README.md index 916348bc..2bab12a1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Time Tracker Time Tracker is a simple web application to track time spent on tasks. It allows you to start a session, stop it, and view completed sessions with start time, end time, and duration. -The backend is built with **Rust** and **Axum**, and the frontend is built with **React**. +The backend is built with **Rust** and **Axum**, and the frontend is built with **React**. The frontend is deployed to GitHub Pages from the `prod` branch. --- @@ -54,13 +54,23 @@ npm install npm start ``` +## Deployment + +The frontend is deployed automatically to GitHub Pages from the prod branch. +Visit your app at: https://ldbach.github.io/time-tracker/ + +To deploy manually: + +```bash +git checkout prod +npm run deploy +``` + +The backend is deployed on Render and accessible at: https://time-tracker-onge.onrender.com + ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. -Please make sure to update tests as appropriate. - -## License - -[MIT](https://choosealicense.com/licenses/mit/) \ No newline at end of file +Please make sure to update tests as appropriate. \ No newline at end of file diff --git a/time-tracker-frontend/src/App.js b/time-tracker-frontend/src/App.js index b4d8f900..c9f8ef05 100644 --- a/time-tracker-frontend/src/App.js +++ b/time-tracker-frontend/src/App.js @@ -10,7 +10,7 @@ function App() { const [sessions, setSessions] = useState([]); const fetchSessions = async () => { - const res = await fetch("http://127.0.0.1:3001/sessions"); + const res = await fetch("https://time-tracker-onge.onrender.com/sessions"); const data = await res.json(); // Map backend fields to frontend expected fields @@ -51,7 +51,7 @@ function App() { // Load initial status from backend useEffect(() => { - fetch("http://127.0.0.1:3001/status") + fetch("https://time-tracker-onge.onrender.com/status") .then(res => res.json()) .then(data => setStatus(data)); @@ -75,14 +75,14 @@ function App() { // Start session const startSession = async () => { - const res = await fetch("http://127.0.0.1:3001/start", { method: "POST" }); + const res = await fetch("https://time-tracker-onge.onrender.com/start", { method: "POST" }); const data = await res.json(); setStatus(data); }; // Stop session const stopSession = async () => { - const res = await fetch("http://127.0.0.1:3001/stop", { method: "POST" }); + const res = await fetch("https://time-tracker-onge.onrender.com/stop", { method: "POST" }); await res.json(); setStatus({ @@ -100,7 +100,7 @@ function App() { console.log(id); try { // Call backend to delete session - await fetch(`http://127.0.0.1:3001/sessions/${id}`, { + await fetch(`https://time-tracker-onge.onrender.com/sessions/${id}`, { method: "DELETE", }); diff --git a/time_tracker_backend/src/main.rs b/time_tracker_backend/src/main.rs index 7447aacb..2f099568 100644 --- a/time_tracker_backend/src/main.rs +++ b/time_tracker_backend/src/main.rs @@ -18,6 +18,7 @@ use tokio::sync::Mutex; use axum::routing::delete; // for DELETE routes use axum::extract::Path; // for extracting path parameter use axum::http::Method; +use std::env; #[tokio::main] async fn main() { @@ -64,10 +65,18 @@ async fn main() { .layer(axum::middleware::from_fn(cors_middleware)) .layer(Extension(state.clone())); - let listener = tokio::net::TcpListener::bind("127.0.0.1:3001") + // Get the port from environment or fallback to 3001 locally + // Get the Render-assigned port, fallback to 3001 locally + let port: u16 = env::var("PORT") + .unwrap_or_else(|_| "3001".to_string()) + .parse() + .expect("PORT must be a number"); + let addr = format!("0.0.0.0:{}", port); + + let listener = tokio::net::TcpListener::bind(&addr) .await .unwrap(); - println!("Time Tracker backend running at http://127.0.0.1:3001"); + println!("Time Tracker backend running at http://{}", addr); axum::serve(listener, app).await.unwrap(); }