Commit 6c4d1833 authored by Janos Guljas's avatar Janos Guljas

adjust api and debug api routers

parent fc41140a
...@@ -17,20 +17,24 @@ import ( ...@@ -17,20 +17,24 @@ import (
) )
func (s *server) setupRouting() { func (s *server) setupRouting() {
baseRouter := mux.NewRouter() router := mux.NewRouter()
router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
jsonhttp.NotFound(w, nil)
})
baseRouter.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "User-agent: *\nDisallow: /") fmt.Fprintln(w, "User-agent: *\nDisallow: /")
}) })
baseRouter.Handle("/pingpong/{peer-id}", jsonhttp.MethodHandler{ router.Handle("/pingpong/{peer-id}", jsonhttp.MethodHandler{
"POST": http.HandlerFunc(s.pingpongHandler), "POST": http.HandlerFunc(s.pingpongHandler),
}) })
s.Handler = web.ChainHandlers( s.Handler = web.ChainHandlers(
logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "api access"), logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "api access"),
handlers.CompressHandler, handlers.CompressHandler,
// todo: add recovery handler
s.pageviewMetricsHandler, s.pageviewMetricsHandler,
web.FinalHandler(baseRouter), web.FinalHandler(router),
) )
} }
...@@ -19,39 +19,43 @@ import ( ...@@ -19,39 +19,43 @@ import (
) )
func (s *server) setupRouting() { func (s *server) setupRouting() {
internalBaseRouter := http.NewServeMux() baseRouter := http.NewServeMux()
internalBaseRouter.Handle("/metrics", promhttp.InstrumentMetricHandler( baseRouter.Handle("/metrics", promhttp.InstrumentMetricHandler(
s.metricsRegistry, s.metricsRegistry,
promhttp.HandlerFor(s.metricsRegistry, promhttp.HandlerOpts{}), promhttp.HandlerFor(s.metricsRegistry, promhttp.HandlerOpts{}),
)) ))
internalRouter := mux.NewRouter() router := mux.NewRouter()
internalBaseRouter.Handle("/", web.ChainHandlers( router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "debug api access"), jsonhttp.NotFound(w, nil)
handlers.CompressHandler, })
web.NoCacheHeadersHandler,
web.FinalHandler(internalRouter),
))
internalRouter.Handle("/", http.NotFoundHandler())
internalRouter.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) router.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
internalRouter.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) router.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
internalRouter.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) router.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
internalRouter.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) router.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
internalRouter.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) router.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
internalRouter.Handle("/debug/vars", expvar.Handler()) router.Handle("/debug/vars", expvar.Handler())
internalRouter.HandleFunc("/health", s.statusHandler) router.HandleFunc("/health", s.statusHandler)
internalRouter.HandleFunc("/readiness", s.statusHandler) router.HandleFunc("/readiness", s.statusHandler)
internalRouter.Handle("/connect/{multi-address:.+}", jsonhttp.MethodHandler{ router.Handle("/connect/{multi-address:.+}", jsonhttp.MethodHandler{
"POST": http.HandlerFunc(s.peerConnectHandler), "POST": http.HandlerFunc(s.peerConnectHandler),
}) })
internalRouter.Handle("/peers/{address}", jsonhttp.MethodHandler{ router.Handle("/peers/{address}", jsonhttp.MethodHandler{
"DELETE": http.HandlerFunc(s.peerDisconnectHandler), "DELETE": http.HandlerFunc(s.peerDisconnectHandler),
}) })
s.Handler = internalBaseRouter baseRouter.Handle("/", web.ChainHandlers(
logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "debug api access"),
handlers.CompressHandler,
// todo: add recovery handler
web.NoCacheHeadersHandler,
web.FinalHandler(router),
))
s.Handler = baseRouter
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment