feat(router): add NotFoundHandler for invalid routes
Add a default handler for invalid routes that logs the request details and returns a 404 response. This improves error handling and user experience by providing clear feedback for invalid paths.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"super-frpc/postLog"
|
"super-frpc/postLog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,4 +30,12 @@ func setupRoutes() {
|
|||||||
http.HandleFunc("/frpcAct/instanceMgr/modify", ModifyInstanceHandler)
|
http.HandleFunc("/frpcAct/instanceMgr/modify", ModifyInstanceHandler)
|
||||||
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
|
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
|
||||||
http.HandleFunc("/frpcAct/proxyMgr/create", CreateProxyHandler)
|
http.HandleFunc("/frpcAct/proxyMgr/create", CreateProxyHandler)
|
||||||
|
|
||||||
|
http.HandleFunc("/", NotFoundHandler)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
postLog.Error(fmt.Sprintf("Route not found: %s %s", r.Method, r.URL.Path))
|
||||||
|
SendErrorResponse(w, http.StatusNotFound, "Invalid request path")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user