Add basic logger
This commit is contained in:
parent
c37d249837
commit
8bd2ef4e62
@ -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
14
main.go
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user