Refactor mux setup and fix ReverseProxyInit typo

- Reorganized HTTP mux initialization to clarify plugin and webmin UI routing, replacing parentMux with entryMux.
- Fixed typo in ReverseProxyInit function name and updated its usage in main.go.
This commit is contained in:
Toby Chui
2025-09-13 23:46:38 +08:00
parent 6efab48d33
commit 2a6f4d52b2
2 changed files with 10 additions and 14 deletions

View File

@@ -99,8 +99,9 @@ func main() {
} }
nodeUUID = string(uuidBytes) nodeUUID = string(uuidBytes)
//Create a new webmin mux and csrf middleware layer //Create a new webmin mux, plugin mux and csrf middleware layer
webminPanelMux = http.NewServeMux() webminPanelMux = http.NewServeMux()
pluginAPIMux := http.NewServeMux()
csrfMiddleware = csrf.Protect( csrfMiddleware = csrf.Protect(
[]byte(nodeUUID), []byte(nodeUUID),
csrf.CookieName(CSRF_COOKIENAME), csrf.CookieName(CSRF_COOKIENAME),
@@ -112,24 +113,19 @@ func main() {
//Startup all modules, see start.go //Startup all modules, see start.go
startupSequence() startupSequence()
//Initiate management interface APIs //Initiate APIs
requireAuth = !(*noauth) requireAuth = !(*noauth)
initAPIs(webminPanelMux) initAPIs(webminPanelMux)
// Create a new plugin API mux
pluginAPIMux := http.NewServeMux()
initRestAPI(pluginAPIMux) initRestAPI(pluginAPIMux)
// Create a parent mux to route /plugin endpoints without CSRF, others with CSRF // Create a entry mux to accept all management interface requests
parentMux := http.NewServeMux() entryMux := http.NewServeMux()
// /plugin (rest API) endpoints: no CSRF entryMux.Handle("/plugin/", pluginAPIMux) //For plugins API access
parentMux.Handle("/plugin/", pluginAPIMux) entryMux.Handle("/", csrfMiddleware(webminPanelMux)) //For webmin UI access, require csrf token
// all other endpoints: with CSRF
parentMux.Handle("/", csrfMiddleware(webminPanelMux))
// Start the reverse proxy server in go routine // Start the reverse proxy server in go routine
go func() { go func() {
ReverseProxtInit() ReverseProxyInit()
}() }()
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
@@ -144,7 +140,7 @@ func main() {
SystemWideLogger.Println(SYSTEM_NAME + " started. Visit control panel at http://" + *webUIPort) SystemWideLogger.Println(SYSTEM_NAME + " started. Visit control panel at http://" + *webUIPort)
} }
err = http.ListenAndServe(*webUIPort, parentMux) err = http.ListenAndServe(*webUIPort, entryMux)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@@ -26,7 +26,7 @@ var (
) )
// Add user customizable reverse proxy // Add user customizable reverse proxy
func ReverseProxtInit() { func ReverseProxyInit() {
/* /*
Load Reverse Proxy Global Settings Load Reverse Proxy Global Settings
*/ */