Add basic logger
This commit is contained in:
parent
c37d249837
commit
8bd2ef4e62
@ -18,7 +18,7 @@
|
||||
in {
|
||||
ts-reverse-proxy = pkgs.buildGoModule {
|
||||
pname = "ts-reverse-proxy";
|
||||
version = "v0.0.0";
|
||||
version = "v0.0.1";
|
||||
src = ./.;
|
||||
|
||||
vendorSha256 = "sha256-QcuL7qjNTloLBYnT2pZtYDZlj2/qm8sNS7EUVBbCp7U=";
|
||||
|
14
main.go
14
main.go
@ -8,11 +8,24 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"tailscale.com/client/tailscale"
|
||||
"tailscale.com/tsnet"
|
||||
)
|
||||
|
||||
func httpLog(r *http.Request) {
|
||||
n := time.Now()
|
||||
fmt.Printf("%s (%s) [%s] \"%s %s\" %03d\n",
|
||||
r.RemoteAddr,
|
||||
n.Format(time.RFC822Z),
|
||||
r.Method,
|
||||
r.URL.Path,
|
||||
r.Proto,
|
||||
r.ContentLength,
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
sName := flag.String("name", "", "server name we will be reverse proxying for")
|
||||
cIP := flag.String("ip", "127.0.0.1", "ip address to reverse proxy to")
|
||||
@ -43,6 +56,7 @@ func main() {
|
||||
req.Header.Add("X-Origin-Host", rpURL.Host)
|
||||
req.URL.Scheme = rpURL.Scheme
|
||||
req.URL.Host = rpURL.Host
|
||||
httpLog(req)
|
||||
}}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
Loading…
Reference in New Issue
Block a user