Built-in SSL to get rid of NGINX
Some checks are pending
CI / build (push) Waiting to run

This commit is contained in:
Fijxu 2024-10-04 20:56:01 -03:00
parent dd668e035f
commit 885be2b2ab
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

25
main.go
View file

@ -304,6 +304,8 @@ func RelativeUrl(in string) (newurl string) {
func main() {
var sock string
var port string
var cert string
var key string
path_prefix = os.Getenv("PREFIX_PATH")
@ -319,14 +321,13 @@ func main() {
// }
// }
flag.StringVar(&sock, "s", "/run/http-proxy.sock", "Specify a socket name")
flag.StringVar(&cert, "tls-cert", "", "TLS Certificate path")
flag.StringVar(&key, "tls-key", "", "TLS Certificate Key path")
var https = flag.Bool("https", false, "Use built-in https server")
flag.StringVar(&sock, "s", "/tmp/http-ytproxy.sock", "Specify a socket name")
flag.StringVar(&port, "p", "8080", "Specify a port number")
flag.Parse()
socket := string(sock)
syscall.Unlink(socket)
listener, err := net.Listen("unix", socket)
srv := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 1 * time.Hour,
@ -334,6 +335,10 @@ func main() {
Handler: &requesthandler{},
}
socket := string(sock)
syscall.Unlink(socket)
listener, err := net.Listen("unix", socket)
if err != nil {
fmt.Println("Failed to bind to UDS, please check the socket name, falling back to TCP/IP")
fmt.Println(err.Error())
@ -353,6 +358,14 @@ func main() {
fmt.Println("Setting socket permissions to 777")
}
go srv.Serve(listener)
srv.ListenAndServe()
if *https {
if err := srv.ListenAndServeTLS(cert, key); err != nil {
log.Fatal(err)
}
fmt.Println("Serving HTTPS")
} else {
fmt.Println("Serving HTTP")
srv.ListenAndServe()
}
}
}