1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package main
import (
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"os"
"github.com/peterbourgon/ff/v3"
"go.jolheiser.com/ffjsonnet"
"go.jolheiser.com/tailroute"
)
func main() {
args, fs := Flags()
fs.String("config", "tailproxy.jsonnet", "Config file")
if err := ff.Parse(fs, os.Args[1:],
ff.WithConfigFileFlag("config"),
ff.WithAllowMissingConfigFile(true),
ff.WithConfigFileParser(ffjsonnet.Parser),
); err != nil {
panic(err)
}
os.Setenv("TS_AUTHKEY", args.AuthKey)
proxyURL, err := url.Parse(fmt.Sprintf("http://localhost:%d", args.Port))
if err != nil {
panic(err)
}
proxy := httputil.NewSingleHostReverseProxy(proxyURL)
handler := http.HandlerFunc(proxy.ServeHTTP)
r := tailroute.Router{
Tailnet: handler,
}
if args.Funnel {
r.Funnel = handler
}
if err := r.Serve(args.Hostname, args.DataDir); err != nil {
panic(err)
}
}
|