feat: handle X-Forward-For for log output
- add Gorilla handlers package for enhanced HTTP handling - refactor HTTP server to use a new ServeMux for routing - update ListenAndServe to utilize ProxyHeaders for better proxy support - add RealIP field to client model - use RealIP fild for connect/disconnect log output
This commit is contained in:
parent
dd9490bb3b
commit
44a64bfce4
6 changed files with 17 additions and 7 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/handlers"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
|
@ -43,14 +44,15 @@ func Start() {
|
|||
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
|
||||
|
||||
// start connection handler and broadcast
|
||||
http.HandleFunc("/ws", websocket.HandleConnection)
|
||||
r := http.NewServeMux()
|
||||
r.HandleFunc("/ws", websocket.HandleConnection)
|
||||
go websocket.SendPermanentBroadCastMessage()
|
||||
|
||||
log.Info("GoTomato started", "version", metadata.GoTomatoVersion)
|
||||
log.Info("Websocket listening", "address", listen)
|
||||
|
||||
// start the listener
|
||||
err := http.ListenAndServe(listen, nil)
|
||||
err := http.ListenAndServe(listen, handlers.ProxyHeaders(r))
|
||||
if err != nil {
|
||||
log.Fatal("Error starting server:", "msg", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue