-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement colors for me and swimmer on cluster map (#184)
* feat: implement colors for me and swimmer on cluster map * chore: disable debug logging in production * fix: typescript TS2349 error on apollo * refactor: apollo cookie getter is now cached * chore: ignore typescript due to an issue with nextjs
- Loading branch information
Showing
10 changed files
with
128 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
"runtime/debug" | ||
"time" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// responseWriter is a minimal wrapper for http.ResponseWriter that allows the | ||
// written HTTP status code to be captured for logging. | ||
type responseWriter struct { | ||
http.ResponseWriter | ||
status int | ||
wroteHeader bool | ||
} | ||
|
||
func wrapResponseWriter(w http.ResponseWriter) *responseWriter { | ||
return &responseWriter{ResponseWriter: w} | ||
} | ||
|
||
func (rw *responseWriter) Status() int { | ||
return rw.status | ||
} | ||
|
||
func (rw *responseWriter) WriteHeader(code int) { | ||
if rw.wroteHeader { | ||
return | ||
} | ||
|
||
rw.status = code | ||
rw.ResponseWriter.WriteHeader(code) | ||
rw.wroteHeader = true | ||
} | ||
|
||
// LoggingMiddleware logs the incoming HTTP request & its duration. | ||
func LoggingMiddleware(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
log.Error().Err(err.(error)).Interface("trace", debug.Stack()).Msg("") | ||
} | ||
}() | ||
|
||
start := time.Now() | ||
wrapped := wrapResponseWriter(w) | ||
next.ServeHTTP(wrapped, r) | ||
log.Debug(). | ||
Str("method", r.Method). | ||
Int("status", wrapped.status). | ||
Str("path", r.URL.EscapedPath()). | ||
Dur("duration", time.Since(start)). | ||
Msg("request processed") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters