Add some logging

This commit is contained in:
Neale Pickett 2022-03-05 15:53:47 -07:00
parent f025cd6761
commit 8dd4fca18e
3 changed files with 14 additions and 4 deletions

View File

@ -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"]

View File

@ -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))
}

1
secret
View File

@ -1 +0,0 @@
goober