feat: auto-restart server when listen addr or admin path changes
Build and Push to GHCR / build-and-push (push) Has been cancelled
Build and Push to GHCR / build-and-push (push) Has been cancelled
When admin config is updated with a new listen_addr or admin_path, the server now automatically performs a graceful restart instead of requiring the user to manually restart the service. - cmd/main.go: refactor into a loop that supports graceful shutdown and restart via http.Server.Shutdown - internal/admin/handlers.go: add SetOnRestart callback, triggered after config save when restart is required - web/static/index.html: remove manual restart alert; auto-redirect to new admin path or show toast if port changed via [HAPI](https://hapi.run) Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
@@ -13,13 +13,18 @@ import (
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
cfg *config.Config
|
||||
cfg *config.Config
|
||||
onRestart func()
|
||||
}
|
||||
|
||||
func NewHandler(cfg *config.Config) *Handler {
|
||||
return &Handler{cfg: cfg}
|
||||
}
|
||||
|
||||
func (h *Handler) SetOnRestart(fn func()) {
|
||||
h.onRestart = fn
|
||||
}
|
||||
|
||||
// GetLinks 获取所有链接
|
||||
func (h *Handler) GetLinks(w http.ResponseWriter, r *http.Request) {
|
||||
links := h.cfg.ListLinks()
|
||||
@@ -226,6 +231,10 @@ func (h *Handler) UpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if restartRequired && h.onRestart != nil {
|
||||
go h.onRestart()
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"listen_addr": h.cfg.ListenAddr,
|
||||
|
||||
Reference in New Issue
Block a user