fix: websockets not working with prometheus middleware
This commit is contained in:
parent
f4e24d9440
commit
b45149d731
1 changed files with 19 additions and 14 deletions
|
|
@ -31,7 +31,6 @@ func NewRouter() {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
r.Use(app_middleware.PrometheusMiddleware)
|
|
||||||
r.Use(middleware.RequestID)
|
r.Use(middleware.RequestID)
|
||||||
r.Use(middleware.RealIP)
|
r.Use(middleware.RealIP)
|
||||||
r.Use(middleware.Logger)
|
r.Use(middleware.Logger)
|
||||||
|
|
@ -46,24 +45,30 @@ func NewRouter() {
|
||||||
MaxAge: 300,
|
MaxAge: 300,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Prometheus
|
// Add Prometheus middleware to all routes except WebSockets
|
||||||
r.Handle("/metrics", promhttp.Handler())
|
r.Group(func(r chi.Router) {
|
||||||
|
r.Use(app_middleware.PrometheusMiddleware)
|
||||||
|
|
||||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
// Prometheus
|
||||||
w.Header().Set("Content-Type", "application/json")
|
r.Handle("/metrics", promhttp.Handler())
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
|
||||||
"name": "trafficlunar's api",
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
"url": "https://github.com/trafficlunar/api",
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
|
"name": "trafficlunar's api",
|
||||||
|
"url": "https://github.com/trafficlunar/api",
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.Get("/hit", handler.HandleGetHitCounter)
|
||||||
|
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/hit", handler.HandlePatchHitCounter)
|
||||||
|
r.Get("/song", handler.HandleGetCurrentlyPlaying)
|
||||||
|
r.Get("/projects", handler.HandleGetProjects)
|
||||||
|
r.Get("/computer", handler.HandleComputerGraphData)
|
||||||
|
r.Get("/roblox/grow-a-robloxian/likes", handler.HandleGetGrowARobloxianLikesCount)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/hit", handler.HandleGetHitCounter)
|
|
||||||
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/hit", handler.HandlePatchHitCounter)
|
|
||||||
r.Get("/song", handler.HandleGetCurrentlyPlaying)
|
|
||||||
r.Get("/projects", handler.HandleGetProjects)
|
|
||||||
r.Get("/computer", handler.HandleComputerGraphData)
|
|
||||||
r.Get("/computer/ws", handler.HandleComputerWebSocket)
|
r.Get("/computer/ws", handler.HandleComputerWebSocket)
|
||||||
r.Get("/roblox/grow-a-robloxian/likes", handler.HandleGetGrowARobloxianLikesCount)
|
|
||||||
|
|
||||||
port := os.Getenv("PORT")
|
port := os.Getenv("PORT")
|
||||||
if len(port) == 0 {
|
if len(port) == 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue