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
|
const defaultInterval = 1000
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerMountPoint("/connections", connectionRouter())
|
||||||
|
}
|
||||||
|
|
||||||
func connectionRouter() http.Handler {
|
func connectionRouter() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
r.Get("/", getConnections)
|
r.Get("/", getConnections)
|
||||||
|
@@ -18,6 +18,10 @@ func SetStatsFunc(s func() tcpip.Stats) {
|
|||||||
_statsFunc = s
|
_statsFunc = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerMountPoint("/netstats", http.HandlerFunc(getNetStats))
|
||||||
|
}
|
||||||
|
|
||||||
func getNetStats(w http.ResponseWriter, r *http.Request) {
|
func getNetStats(w http.ResponseWriter, r *http.Request) {
|
||||||
if _statsFunc == nil {
|
if _statsFunc == nil {
|
||||||
render.Status(r, http.StatusInternalServerError)
|
render.Status(r, http.StatusInternalServerError)
|
||||||
|
@@ -20,10 +20,18 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _upgrader = websocket.Upgrader{
|
var (
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
_upgrader = websocket.Upgrader{
|
||||||
return true
|
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 {
|
func Start(addr, token string) error {
|
||||||
@@ -43,8 +51,10 @@ func Start(addr, token string) error {
|
|||||||
r.Get("/logs", getLogs)
|
r.Get("/logs", getLogs)
|
||||||
r.Get("/traffic", traffic)
|
r.Get("/traffic", traffic)
|
||||||
r.Get("/version", version)
|
r.Get("/version", version)
|
||||||
r.Get("/netstats", getNetStats)
|
// attach HTTP handlers
|
||||||
r.Mount("/connections", connectionRouter())
|
for pattern, handler := range _mountPoints {
|
||||||
|
r.Mount(pattern, handler)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
listener, err := net.Listen("tcp", addr)
|
listener, err := net.Listen("tcp", addr)
|
||||||
|
Reference in New Issue
Block a user