From 0d445c0d527448160eb5e977eacdd7498add117c Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Wed, 8 Nov 2023 20:46:34 -0500 Subject: cmd/xedn: fly region annotation middleware Signed-off-by: Xe Iaso --- cmd/xedn/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/xedn/main.go b/cmd/xedn/main.go index 3ad0624..a6762a8 100644 --- a/cmd/xedn/main.go +++ b/cmd/xedn/main.go @@ -213,6 +213,18 @@ func main() { http.Error(w, "wait, what, how did you do that?", http.StatusBadRequest) }) + var h http.Handler = topLevel + h = xffMW.Handler(h) + h = cors.Default().Handler(h) + h = FlyRegionAnnotation(h) + slog.Info("starting up", "addr", *addr) - http.ListenAndServe(*addr, cors.Default().Handler(xffMW.Handler(topLevel))) + http.ListenAndServe(*addr, h) +} + +func FlyRegionAnnotation(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Fly-Region", os.Getenv("FLY_REGION")) + next.ServeHTTP(w, r) + }) } -- cgit v1.2.3