2023-03-08 20:36:41 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
// The tsnet-funnel server demonstrates how to use tsnet with Funnel.
|
2023-03-10 19:44:28 +00:00
|
|
|
//
|
|
|
|
// To use it, generate an auth key from the Tailscale admin panel and
|
|
|
|
// run the demo with the key:
|
|
|
|
//
|
|
|
|
// TS_AUTHKEY=<yourkey> go run tsnet-funnel.go
|
2023-03-08 20:36:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"tailscale.com/tsnet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2023-03-10 19:44:28 +00:00
|
|
|
s := &tsnet.Server{
|
2023-03-11 16:45:40 +00:00
|
|
|
Dir: "./funnel-demo-config",
|
2023-03-10 19:44:28 +00:00
|
|
|
Hostname: "fun",
|
2023-03-08 20:36:41 +00:00
|
|
|
}
|
2023-03-10 19:44:28 +00:00
|
|
|
defer s.Close()
|
2023-03-08 20:36:41 +00:00
|
|
|
|
2023-03-10 19:44:28 +00:00
|
|
|
ln, err := s.ListenFunnel("tcp", ":443")
|
2023-03-08 20:36:41 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer ln.Close()
|
|
|
|
|
2023-03-11 21:12:57 +00:00
|
|
|
fmt.Printf("Listening on https://%v\n", s.CertDomains()[0])
|
|
|
|
|
2023-03-10 19:44:28 +00:00
|
|
|
err = http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintln(w, "<html><body><h1>Hello, internet!</h1>")
|
|
|
|
}))
|
|
|
|
log.Fatal(err)
|
2023-03-08 20:36:41 +00:00
|
|
|
}
|