feat: 支持局域网 HTTPS 直连并持久化插件连接配置
This commit is contained in:
1 parent
9eba4556db
commit
2203afde3c
15 files changed
+486
-17
No files matched your search
+29
-2
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -142,7 +144,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||
fail := func(e error) { http.Error(w, e.Error(), 400) }
|
||||
if r.URL.Path == "/api/v1/health" {
|
||||
jsonOut(w, map[string]any{"version": "0.1.0", "os": runtime.GOOS, "sync": "http-manifest"})
|
||||
jsonOut(w, map[string]any{"version": "0.1.1", "os": runtime.GOOS, "sync": "http-manifest"})
|
||||
return
|
||||
}
|
||||
if len(parts) < 3 || parts[0] != "api" || parts[1] != "v1" {
|
||||
@@ -509,7 +511,27 @@ func main() {
|
||||
addr := flag.String("listen", "127.0.0.1:8765", "HTTP bind address; use HTTPS proxy or SSH tunnel remotely")
|
||||
root := flag.String("data", "./data", "service data directory")
|
||||
tasks := flag.String("tasks", ":app:assembleDebug", "comma separated allowed Gradle tasks")
|
||||
cert := flag.String("tls-cert", "", "PEM certificate path")
|
||||
key := flag.String("tls-key", "", "PEM private key path")
|
||||
initHost := flag.String("init-tls-host", "", "generate a local certificate for this IP/hostname and exit")
|
||||
tlsDir := flag.String("tls-dir", "./tls", "certificate output directory")
|
||||
flag.Parse()
|
||||
if *initHost != "" {
|
||||
if e := initCertificate(*initHost, *tlsDir); e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (*cert == "") != (*key == "") {
|
||||
log.Fatal("tls-cert and tls-key must be provided together")
|
||||
}
|
||||
host, _, e := net.SplitHostPort(*addr)
|
||||
if e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
if *cert == "" && host != "localhost" && (net.ParseIP(host) == nil || !net.ParseIP(host).IsLoopback()) {
|
||||
log.Fatal("non-loopback listeners require TLS")
|
||||
}
|
||||
token := os.Getenv("REMOTE_BUILD_TOKEN")
|
||||
if len(token) < 24 {
|
||||
log.Fatal("REMOTE_BUILD_TOKEN must contain at least 24 characters")
|
||||
@@ -555,6 +577,7 @@ func main() {
|
||||
}
|
||||
log.Printf("remotecompile listening on %s (%s)", *addr, runtime.GOOS)
|
||||
srv := &http.Server{Addr: *addr, Handler: s, ReadHeaderTimeout: 10 * time.Second, ReadTimeout: 5 * time.Minute, IdleTimeout: 60 * time.Second}
|
||||
srv.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12}
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
@@ -573,7 +596,11 @@ func main() {
|
||||
defer cancel()
|
||||
srv.Shutdown(ctx)
|
||||
}()
|
||||
if e := srv.ListenAndServe(); e != nil && e != http.ErrServerClosed {
|
||||
serve := srv.ListenAndServe
|
||||
if *cert != "" {
|
||||
serve = func() error { return srv.ListenAndServeTLS(*cert, *key) }
|
||||
}
|
||||
if e := serve(); e != nil && e != http.ErrServerClosed {
|
||||
log.Fatal(e)
|
||||
}
|
||||
// Let workers persist terminal state and clear their active markers.
|
||||
|
||||
Reference in new issue
Block a user