scan flow: fire scan immediately on tag-page load (location is an upgrade, not a gate) so a tag view always records+alerts; add request logging middleware (method/path/status/duration) to stdout for diagnostics
This commit is contained in:
@@ -91,12 +91,31 @@ func main() {
|
|||||||
mux.Handle("POST /account/tags/{id}/photo", app.RequireAuth(app.UploadPhoto))
|
mux.Handle("POST /account/tags/{id}/photo", app.RequireAuth(app.UploadPhoto))
|
||||||
mux.HandleFunc("GET /photos/{key...}", app.ServePhoto)
|
mux.HandleFunc("GET /photos/{key...}", app.ServePhoto)
|
||||||
|
|
||||||
|
// Request logging: every hit (method, path, status, duration) goes to stdout
|
||||||
|
// so we can see exactly what phones send (diagnostics for the scan flow).
|
||||||
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
start := time.Now()
|
||||||
|
rec := &statusRecorder{ResponseWriter: w, status: 200}
|
||||||
|
mux.ServeHTTP(rec, r)
|
||||||
|
log.Printf("%s %s -> %d (%s)", r.Method, r.URL.RequestURI(), rec.status, time.Since(start).Round(time.Millisecond))
|
||||||
|
})
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: mux,
|
Handler: handler,
|
||||||
ReadTimeout: 10 * time.Second,
|
ReadTimeout: 10 * time.Second,
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
log.Println("wherewoof listening on", addr)
|
log.Println("wherewoof listening on", addr)
|
||||||
log.Fatal(srv.ListenAndServe())
|
log.Fatal(srv.ListenAndServe())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type statusRecorder struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
status int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *statusRecorder) WriteHeader(code int) {
|
||||||
|
r.status = code
|
||||||
|
r.ResponseWriter.WriteHeader(code)
|
||||||
|
}
|
||||||
|
|||||||
@@ -145,6 +145,9 @@
|
|||||||
{timeout: 20000, maximumAge: 0}
|
{timeout: 20000, maximumAge: 0}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// Fire a scan immediately so a tag view always reports (and alerts) —
|
||||||
|
// location is an upgrade, never a gate.
|
||||||
|
sendScan(null, null);
|
||||||
if (btn) btn.addEventListener("click", tryLocation);
|
if (btn) btn.addEventListener("click", tryLocation);
|
||||||
tryLocation();
|
tryLocation();
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user