feat(ui): Implement Custom CSS configuration (#943)
* feat(ui): Implement Custom CSS configuration * Update web/app/public/index.html
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/TwiN/gatus/v5/config"
|
||||
"github.com/TwiN/gatus/v5/config/ui"
|
||||
"github.com/TwiN/gatus/v5/config/web"
|
||||
static "github.com/TwiN/gatus/v5/web"
|
||||
"github.com/TwiN/health"
|
||||
@ -31,6 +32,10 @@ func New(cfg *config.Config) *API {
|
||||
logr.Warnf("[api.New] nil web config passed as parameter. This should only happen in tests. Using default web configuration")
|
||||
cfg.Web = web.GetDefaultConfig()
|
||||
}
|
||||
if cfg.UI == nil {
|
||||
logr.Warnf("[api.New] nil ui config passed as parameter. This should only happen in tests. Using default ui configuration")
|
||||
cfg.UI = ui.GetDefaultConfig()
|
||||
}
|
||||
api.router = api.createRouter(cfg)
|
||||
return api
|
||||
}
|
||||
@ -87,6 +92,8 @@ func (a *API) createRouter(cfg *config.Config) *fiber.App {
|
||||
statusCode, body := healthHandler.GetResponseStatusCodeAndBody()
|
||||
return c.Status(statusCode).Send(body)
|
||||
})
|
||||
// Custom CSS
|
||||
app.Get("/css/custom.css", CustomCSSHandler{customCSS: cfg.UI.CustomCSS}.GetCustomCSS)
|
||||
// Everything else falls back on static content
|
||||
app.Use(redirect.New(redirect.Config{
|
||||
Rules: map[string]string{
|
||||
|
@ -25,6 +25,17 @@ func TestNew(t *testing.T) {
|
||||
Path: "/health",
|
||||
ExpectedCode: fiber.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "custom.css",
|
||||
Path: "/css/custom.css",
|
||||
ExpectedCode: fiber.StatusOK,
|
||||
},
|
||||
{
|
||||
Name: "custom.css-gzipped",
|
||||
Path: "/css/custom.css",
|
||||
ExpectedCode: fiber.StatusOK,
|
||||
Gzip: true,
|
||||
},
|
||||
{
|
||||
Name: "metrics",
|
||||
Path: "/metrics",
|
||||
|
14
api/custom_css.go
Normal file
14
api/custom_css.go
Normal file
@ -0,0 +1,14 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type CustomCSSHandler struct {
|
||||
customCSS string
|
||||
}
|
||||
|
||||
func (handler CustomCSSHandler) GetCustomCSS(c *fiber.Ctx) error {
|
||||
c.Set("Content-Type", "text/css")
|
||||
return c.Status(200).SendString(handler.customCSS)
|
||||
}
|
Reference in New Issue
Block a user