mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-05 16:05:36 +00:00
958c89470b
Signed-off-by: Maisem Ali <maisem@tailscale.com>
44 lines
901 B
Go
44 lines
901 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// The tsnet-funnel server demonstrates how to use tsnet with Funnel.
|
|
//
|
|
// 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
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"tailscale.com/tsnet"
|
|
"tailscale.com/types/logger"
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
s := &tsnet.Server{
|
|
Dir: "./funnel-demo-config",
|
|
Logf: logger.Discard,
|
|
Hostname: "fun",
|
|
}
|
|
defer s.Close()
|
|
|
|
ln, err := s.ListenFunnel("tcp", ":443")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer ln.Close()
|
|
|
|
fmt.Printf("Listening on https://%v\n", s.CertDomains()[0])
|
|
|
|
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)
|
|
}
|