diff --git a/cmd/main.go b/cmd/main.go index 6ecb88c..47a6e25 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -128,6 +128,10 @@ func main() { http.Handle("/", http.FileServer(http.Dir("./static"))) + http.HandleFunc("/schema.proto", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "./proto/schema.proto") + }) + http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) { vehicles, err := getVehicles() if err != nil { diff --git a/static/index.html b/static/index.html index 88c3dac..52c3779 100644 --- a/static/index.html +++ b/static/index.html @@ -43,25 +43,21 @@ '© OpenStreetMap', }).addTo(map); - protobuf - .load( - "https://raw.githubusercontent.com/cjdenio/uta-trax-api/refs/heads/main/proto/schema.proto" - ) - .then(async (root) => { - const bin = await fetch("/api").then((r) => r.arrayBuffer()); - const { vehicles } = root - .lookupType("VehicleFeed") - .decode(new Uint8Array(bin)); + protobuf.load("/schema.proto").then(async (root) => { + const bin = await fetch("/api").then((r) => r.arrayBuffer()); + const { vehicles } = root + .lookupType("VehicleFeed") + .decode(new Uint8Array(bin)); - vehicles.forEach((vehicle) => { - L.circle([vehicle.lat, vehicle.lon], { - fillColor: COLORS[vehicle.line], - color: COLORS[vehicle.line], - fillOpacity: 0.5, - radius: 200, - }).addTo(map); - }); + vehicles.forEach((vehicle) => { + L.circle([vehicle.lat, vehicle.lon], { + fillColor: COLORS[vehicle.line], + color: COLORS[vehicle.line], + fillOpacity: 0.5, + radius: 200, + }).addTo(map); }); + });