feat: update Go server to serve static files
This commit is contained in:
@@ -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.Println("Trip Planner API starting on :8080")
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,9 +54,9 @@
|
|||||||
- [x] create `static/app.js` with API calls and map rendering logic
|
- [x] create `static/app.js` with API calls and map rendering logic
|
||||||
|
|
||||||
### Task 2: Update Go server to serve static files
|
### Task 2: Update Go server to serve static files
|
||||||
- [ ] update `cmd/api/main.go` to serve static files from `static/` directory
|
- [x] update `cmd/api/main.go` to serve static files from `static/` directory
|
||||||
- [ ] add route for `/static/*` to serve CSS, JS, and other assets
|
- [x] add route for `/static/*` to serve CSS, JS, and other assets
|
||||||
- [ ] add route for `/` or `/index.html` to serve the frontend
|
- [x] add route for `/` or `/index.html` to serve the frontend
|
||||||
|
|
||||||
### Task 3: Verify frontend functionality
|
### Task 3: Verify frontend functionality
|
||||||
- [ ] verify search form works and calls `/v1/routes/search` endpoint
|
- [ ] verify search form works and calls `/v1/routes/search` endpoint
|
||||||
|
|||||||
Reference in New Issue
Block a user