Add some logging
This commit is contained in:
parent
f025cd6761
commit
8dd4fca18e
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1
|
||||
FROM golang:1-alpine AS builder
|
||||
|
||||
WORKDIR /go/src/app
|
||||
COPY . .
|
||||
|
@ -6,4 +6,7 @@ COPY . .
|
|||
RUN go get -d -v ./...
|
||||
RUN go install -v ./...
|
||||
|
||||
CMD ["simpleauth"]
|
||||
FROM alpine
|
||||
COPY --from=builder /go/bin/simpleauth /bin
|
||||
COPY --from=builder /go/src/app/static /static
|
||||
CMD ["/bin/simpleauth"]
|
||||
|
|
|
@ -37,11 +37,19 @@ func rootHandler(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// Log the request
|
||||
clientIP := req.Header.Get("X-Real-IP")
|
||||
if clientIP == "" {
|
||||
clientIP = req.RemoteAddr
|
||||
}
|
||||
log.Println(clientIP, req.Method, req.URL, "authenticated:", authenticated)
|
||||
|
||||
if authenticated {
|
||||
t := token.New(secret, time.Now().Add(lifespan))
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: CookieName,
|
||||
Value: t.String(),
|
||||
Path: "/",
|
||||
Secure: true,
|
||||
SameSite: http.SameSiteStrictMode,
|
||||
})
|
||||
|
@ -112,6 +120,6 @@ func main() {
|
|||
|
||||
http.HandleFunc("/", rootHandler)
|
||||
|
||||
fmt.Println("I am listening on ", *listen)
|
||||
fmt.Println("listening on", *listen)
|
||||
log.Fatal(http.ListenAndServe(*listen, nil))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue