Add basic logger

This commit is contained in:
Aaron Bieber 2023-02-04 07:11:27 -07:00
parent c37d249837
commit 8bd2ef4e62
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View File

@ -18,7 +18,7 @@
in { in {
ts-reverse-proxy = pkgs.buildGoModule { ts-reverse-proxy = pkgs.buildGoModule {
pname = "ts-reverse-proxy"; pname = "ts-reverse-proxy";
version = "v0.0.0"; version = "v0.0.1";
src = ./.; src = ./.;
vendorSha256 = "sha256-QcuL7qjNTloLBYnT2pZtYDZlj2/qm8sNS7EUVBbCp7U="; vendorSha256 = "sha256-QcuL7qjNTloLBYnT2pZtYDZlj2/qm8sNS7EUVBbCp7U=";

14
main.go
View File

@ -8,11 +8,24 @@ import (
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"time"
"tailscale.com/client/tailscale" "tailscale.com/client/tailscale"
"tailscale.com/tsnet" "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() { func main() {
sName := flag.String("name", "", "server name we will be reverse proxying for") 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") 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.Header.Add("X-Origin-Host", rpURL.Host)
req.URL.Scheme = rpURL.Scheme req.URL.Scheme = rpURL.Scheme
req.URL.Host = rpURL.Host req.URL.Host = rpURL.Host
httpLog(req)
}} }}
mux := http.NewServeMux() mux := http.NewServeMux()