🎨 Improve http server

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-12-09 11:02:25 +08:00
parent 21dff696cc
commit 106a679dba
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 10 additions and 1 deletions

View file

@ -745,6 +745,9 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
if nil != util.WebSocketServer {
util.WebSocketServer.Close()
}
if nil != util.HttpServer {
util.HttpServer.Close()
}
util.HttpServing = false
if util.ContainerAndroid == util.Container {

View file

@ -217,7 +217,11 @@ func Serve(fastMode bool) {
// 反代服务器启动失败不影响核心服务器启动
}()
if err = http.Serve(ln, ginServer.Handler()); err != nil {
util.HttpServer = &http.Server{
Handler: ginServer,
}
if err = util.HttpServer.Serve(ln); err != nil {
if !fastMode {
logging.LogErrorf("boot kernel failed: %s", err)
os.Exit(logging.ExitCodeUnavailablePort)

View file

@ -22,6 +22,7 @@ import (
"fmt"
"math/rand"
"mime"
"net/http"
"net/url"
"os"
"path/filepath"
@ -72,6 +73,7 @@ func initEnvVars() {
var (
bootProgress = atomic.Int32{} // 启动进度,从 0 到 100
bootDetails string // 启动细节描述
HttpServer *http.Server // HTTP 伺服器实例
HttpServing = false // 是否 HTTP 伺服已经可用
)