Files
backend/router.go
T
NanamiAdmin 1f426f98e5 refactor(api): simplify instance management endpoints
- Change delete endpoint to use request body instead of path parameter
- Modify endpoint now takes field as path parameter and instance name in body
- Update README to reflect API changes
- Remove unused description field from software info
- Fix error message in auth token lookup
2026-02-28 11:55:52 +08:00

63 lines
1.4 KiB
Go

package main
import (
"net/http"
"strings"
"super-frpc/postLog"
)
func setupRoutes() {
postLog.Info("Setting up routes...")
http.HandleFunc("/register", RegisterHandler)
http.HandleFunc("/login", LoginHandler)
http.HandleFunc("/frpcAct/instanceMgr/create", CreateInstanceHandler)
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
http.HandleFunc("/frpcAct/instanceMgr/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if len(path) < len("/frpcAct/instanceMgr/") {
SendErrorResponse(w, http.StatusNotFound, "invalid path")
return
}
remainingPath := path[len("/frpcAct/instanceMgr/"):]
if r.Method == http.MethodGet {
if remainingPath == "list" {
ListInstancesHandler(w, r)
return
}
instanceName := strings.Trim(remainingPath, "/")
if instanceName != "" {
ListInstancesHandler(w, r)
return
}
}
if r.Method == http.MethodPost {
if remainingPath == "create" {
CreateInstanceHandler(w, r)
return
}
if remainingPath == "delete" {
DeleteInstanceHandler(w, r)
return
}
if strings.HasPrefix(remainingPath, "modify/") {
parts := strings.SplitN(remainingPath, "/", 2)
if len(parts) == 2 {
field := parts[1]
ModifyInstanceHandler(w, r, field)
return
}
}
}
SendErrorResponse(w, http.StatusNotFound, "endpoint not found")
})
}