🎨 桌面端内核进程使用随机端口 https://github.com/siyuan-note/siyuan/issues/4952
This commit is contained in:
parent
b75b878ff3
commit
14dcf78cd9
1 changed files with 14 additions and 1 deletions
|
@ -20,7 +20,9 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/http/pprof"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -79,7 +81,7 @@ func Serve(fastMode bool) {
|
|||
host = "127.0.0.1"
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", ":"+util.ServerPort)
|
||||
ln, err := net.Listen("tcp", host+":"+util.ServerPort)
|
||||
if nil != err {
|
||||
if !fastMode {
|
||||
logging.LogErrorf("boot kernel failed: %s", err)
|
||||
|
@ -103,6 +105,17 @@ func Serve(fastMode bool) {
|
|||
logging.LogInfof("kernel [pid=%s] is booting [%s]", pid, "http://"+host+":"+port)
|
||||
util.HttpServing = true
|
||||
|
||||
go func() {
|
||||
if util.FixedPort != port {
|
||||
serverURL, _ := url.Parse("http://" + host + ":" + port)
|
||||
proxy := httputil.NewSingleHostReverseProxy(serverURL)
|
||||
logging.LogInfof("kernel reverse proxy server [%s] is booting", util.FixedPort)
|
||||
if proxyErr := http.ListenAndServe(host+":"+util.FixedPort, proxy); nil != proxyErr {
|
||||
logging.LogErrorf("boot kernel reverse proxy server failed: %s", serverURL, proxyErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err = http.Serve(ln, ginServer); nil != err {
|
||||
if !fastMode {
|
||||
logging.LogErrorf("boot kernel failed: %s", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue