2022-05-11 18:47:31 -04:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
h "npm/internal/api/http"
|
|
|
|
"npm/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EnforceSetup will error if the config setup doesn't match what is required
|
2024-09-11 01:03:00 -04:00
|
|
|
func EnforceSetup() func(http.Handler) http.Handler {
|
2022-05-11 18:47:31 -04:00
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2024-09-11 01:03:00 -04:00
|
|
|
if !config.IsSetup {
|
|
|
|
h.ResultErrorJSON(w, r, http.StatusForbidden, "Not available during setup phase", nil)
|
2022-05-11 18:47:31 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// All good
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|