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:
10
router.go
10
router.go
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"super-frpc/postLog"
|
||||
)
|
||||
|
||||
@@ -30,4 +30,12 @@ func setupRoutes() {
|
||||
http.HandleFunc("/frpcAct/instanceMgr/modify", ModifyInstanceHandler)
|
||||
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
|
||||
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