diff --git a/Dockerfile b/Dockerfile index 8f58401a3823fefbcc0924b0c350f9e02d763317..cf7f589b02d0798ba44126c249a2d10cfb778e50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ RUN apk add --no-cache curl git gcc musl-dev RUN curl https://glide.sh/get | sh WORKDIR /go/src/app -COPY *.go . -COPY glide.* . +COPY *.go ./ +COPY glide.* ./ RUN glide install RUN CGO_ENABLED=false go build -a app . diff --git a/main.go b/main.go index 5dbedac19de23f78a2238797664a98d3a5dbdd4c..127f7bd69014bfb55c4992ce80035b7a9a307f61 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,19 @@ import ( "github.com/go-redis/redis" _ "github.com/lib/pq" "net/http" + "fmt" ) +func headerWrapper(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + println(r.URL.Path) + for key, value := range r.Header { + fmt.Printf("%s: %s", key, value) + } + handler.ServeHTTP(w, r) + }) +} + func main() { config := NewConfigFromEnv() @@ -26,17 +37,17 @@ func main() { http.FileServer(http.Dir("assets")), } - http.Handle("/upload/", pageUpload(pageContext)) + http.Handle("/upload/", headerWrapper(pageUpload(pageContext))) - http.Handle("/i/", http.StripPrefix("/i/", pageImageDetail(pageContext))) - http.Handle("/me/i/", http.StripPrefix("/me/i/", pageImageDetail(pageContext))) + http.Handle("/i/", headerWrapper(http.StripPrefix("/i/", pageImageDetail(pageContext)))) + http.Handle("/me/i/", headerWrapper(http.StripPrefix("/me/i/", pageImageDetail(pageContext)))) - http.Handle("/a/", http.StripPrefix("/a/", pageAlbumDetail(pageContext))) - http.Handle("/me/a/", http.StripPrefix("/me/a/", pageAlbumDetail(pageContext))) + http.Handle("/a/", headerWrapper(http.StripPrefix("/a/", pageAlbumDetail(pageContext)))) + http.Handle("/me/a/", headerWrapper(http.StripPrefix("/me/a/", pageAlbumDetail(pageContext)))) - http.Handle("/me/images/", pageImageList(pageContext)) - http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets")))) - http.Handle("/", pageIndex(pageContext)) + http.Handle("/me/images/", headerWrapper(pageImageList(pageContext))) + http.Handle("/assets/", headerWrapper(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))) + http.Handle("/", headerWrapper(pageIndex(pageContext))) http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("OK"))