mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-06 01:07:03 +08:00
Fix(restapi): debug missing mountpoints
This commit is contained in:
@@ -16,6 +16,10 @@ import (
|
||||
|
||||
const defaultInterval = 1000
|
||||
|
||||
func init() {
|
||||
registerMountPoint("/connections", connectionRouter())
|
||||
}
|
||||
|
||||
func connectionRouter() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Get("/", getConnections)
|
||||
|
@@ -18,6 +18,10 @@ func SetStatsFunc(s func() tcpip.Stats) {
|
||||
_statsFunc = s
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerMountPoint("/netstats", http.HandlerFunc(getNetStats))
|
||||
}
|
||||
|
||||
func getNetStats(w http.ResponseWriter, r *http.Request) {
|
||||
if _statsFunc == nil {
|
||||
render.Status(r, http.StatusInternalServerError)
|
||||
|
@@ -20,10 +20,18 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var _upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
var (
|
||||
_upgrader = websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
_mountPoints = make(map[string]http.Handler)
|
||||
)
|
||||
|
||||
func registerMountPoint(pattern string, handler http.Handler) {
|
||||
_mountPoints[pattern] = handler
|
||||
}
|
||||
|
||||
func Start(addr, token string) error {
|
||||
@@ -43,8 +51,10 @@ func Start(addr, token string) error {
|
||||
r.Get("/logs", getLogs)
|
||||
r.Get("/traffic", traffic)
|
||||
r.Get("/version", version)
|
||||
r.Get("/netstats", getNetStats)
|
||||
r.Mount("/connections", connectionRouter())
|
||||
// attach HTTP handlers
|
||||
for pattern, handler := range _mountPoints {
|
||||
r.Mount(pattern, handler)
|
||||
}
|
||||
})
|
||||
|
||||
listener, err := net.Listen("tcp", addr)
|
||||
|
Reference in New Issue
Block a user