mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-26 17:38:14 -07:00
Add ping route for http listener
This commit is contained in:
Vendored
+6
@@ -63,6 +63,12 @@ mochi:
|
|||||||
- "/scrape"
|
- "/scrape"
|
||||||
# - "/scrape.php"
|
# - "/scrape.php"
|
||||||
|
|
||||||
|
# An array of routes to listen ping requests.
|
||||||
|
# Used just to ensure if server is operational. Returns nothing,
|
||||||
|
# just HTTP 200 without body. Listens both GET and HEAD HTTP methods.
|
||||||
|
ping_routes:
|
||||||
|
- "/ping"
|
||||||
|
|
||||||
# When enabled, the IP address used to connect to the tracker will not
|
# When enabled, the IP address used to connect to the tracker will not
|
||||||
# override the value clients advertise as their IP address.
|
# override the value clients advertise as their IP address.
|
||||||
allow_ip_spoofing: false
|
allow_ip_spoofing: false
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Config struct {
|
|||||||
TLSKeyPath string `yaml:"tls_key_path"`
|
TLSKeyPath string `yaml:"tls_key_path"`
|
||||||
AnnounceRoutes []string `yaml:"announce_routes"`
|
AnnounceRoutes []string `yaml:"announce_routes"`
|
||||||
ScrapeRoutes []string `yaml:"scrape_routes"`
|
ScrapeRoutes []string `yaml:"scrape_routes"`
|
||||||
|
PingRoutes []string `yaml:"ping_routes"`
|
||||||
EnableRequestTiming bool `yaml:"enable_request_timing"`
|
EnableRequestTiming bool `yaml:"enable_request_timing"`
|
||||||
ParseOptions `yaml:",inline"`
|
ParseOptions `yaml:",inline"`
|
||||||
}
|
}
|
||||||
@@ -48,6 +49,7 @@ func (cfg Config) LogFields() log.Fields {
|
|||||||
"tlsKeyPath": cfg.TLSKeyPath,
|
"tlsKeyPath": cfg.TLSKeyPath,
|
||||||
"announceRoutes": cfg.AnnounceRoutes,
|
"announceRoutes": cfg.AnnounceRoutes,
|
||||||
"scrapeRoutes": cfg.ScrapeRoutes,
|
"scrapeRoutes": cfg.ScrapeRoutes,
|
||||||
|
"pingRoutes": cfg.PingRoutes,
|
||||||
"enableRequestTiming": cfg.EnableRequestTiming,
|
"enableRequestTiming": cfg.EnableRequestTiming,
|
||||||
"allowIPSpoofing": cfg.AllowIPSpoofing,
|
"allowIPSpoofing": cfg.AllowIPSpoofing,
|
||||||
"realIPHeader": cfg.RealIPHeader,
|
"realIPHeader": cfg.RealIPHeader,
|
||||||
@@ -184,6 +186,13 @@ func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error
|
|||||||
router.GET(route, f.scrapeRoute)
|
router.GET(route, f.scrapeRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(f.PingRoutes) > 0 {
|
||||||
|
for _, route := range f.PingRoutes {
|
||||||
|
router.GET(route, f.ping)
|
||||||
|
router.HEAD(route, f.ping)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.Addr != "" {
|
if cfg.Addr != "" {
|
||||||
go func() {
|
go func() {
|
||||||
if err := f.serveHTTP(router, false); err != nil {
|
if err := f.serveHTTP(router, false); err != nil {
|
||||||
@@ -364,3 +373,7 @@ func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, ps httpro
|
|||||||
|
|
||||||
go f.logic.AfterScrape(ctx, req, resp)
|
go f.logic.AfterScrape(ctx, req, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f Frontend) ping(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user