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
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

---

Expand Down Expand Up @@ -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/)
Please make sure to update tests as appropriate.
10 changes: 5 additions & 5 deletions time-tracker-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand All @@ -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({
Expand All @@ -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",
});

Expand Down
13 changes: 11 additions & 2 deletions time_tracker_backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}

Expand Down