move middleware to its own file
in anticipation of maybe adding more
This commit is contained in:
parent
df3adcde91
commit
108ba4d8c2
12
cmd/web/middleware.go
Normal file
12
cmd/web/middleware.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Middleware is a slice of Middleware (aka func(n http.Handler) http.Handler {})
|
||||||
|
var Middleware []func(next http.Handler) http.Handler = []func(next http.Handler) http.Handler{
|
||||||
|
middleware.Recoverer,
|
||||||
|
}
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
|
||||||
|
|
||||||
"git.burning.moe/celediel/burning.moe/internal/config"
|
"git.burning.moe/celediel/burning.moe/internal/config"
|
||||||
"git.burning.moe/celediel/burning.moe/internal/handlers"
|
"git.burning.moe/celediel/burning.moe/internal/handlers"
|
||||||
|
@ -16,7 +15,9 @@ func routes(app *config.AppConfig) http.Handler {
|
||||||
mux := chi.NewRouter()
|
mux := chi.NewRouter()
|
||||||
|
|
||||||
// Import some middleware
|
// Import some middleware
|
||||||
mux.Use(middleware.Recoverer)
|
for _, mw := range Middleware {
|
||||||
|
mux.Use(mw)
|
||||||
|
}
|
||||||
|
|
||||||
// Setup static file server
|
// Setup static file server
|
||||||
app.Logger.Debug("Setting up /static file server")
|
app.Logger.Debug("Setting up /static file server")
|
||||||
|
|
Loading…
Reference in a new issue