From b000d7d44f981a88481b0e93fb2362dcfda3dcc3 Mon Sep 17 00:00:00 2001 From: Vladimir Zagainov Date: Tue, 18 Aug 2026 15:19:46 +0300 Subject: [PATCH] feat: update Go server to serve static files --- cmd/api/main.go | 12 ++++++++++++ docs/plans/2026-08-18-implement-leaflet-frontend.md | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/api/main.go b/cmd/api/main.go index 3fc4d97..39c717f 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -68,6 +68,18 @@ func main() { } }) + // Serve static files from static/ directory + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + + // Serve frontend + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" || r.URL.Path == "/index.html" { + http.ServeFile(w, r, "static/index.html") + return + } + http.NotFound(w, r) + }) + log.Println("Trip Planner API starting on :8080") log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/docs/plans/2026-08-18-implement-leaflet-frontend.md b/docs/plans/2026-08-18-implement-leaflet-frontend.md index c85f54a..50a2c72 100644 --- a/docs/plans/2026-08-18-implement-leaflet-frontend.md +++ b/docs/plans/2026-08-18-implement-leaflet-frontend.md @@ -54,9 +54,9 @@ - [x] create `static/app.js` with API calls and map rendering logic ### Task 2: Update Go server to serve static files -- [ ] update `cmd/api/main.go` to serve static files from `static/` directory -- [ ] add route for `/static/*` to serve CSS, JS, and other assets -- [ ] add route for `/` or `/index.html` to serve the frontend +- [x] update `cmd/api/main.go` to serve static files from `static/` directory +- [x] add route for `/static/*` to serve CSS, JS, and other assets +- [x] add route for `/` or `/index.html` to serve the frontend ### Task 3: Verify frontend functionality - [ ] verify search form works and calls `/v1/routes/search` endpoint