web ui: basic logic

This commit is contained in:
2023-04-04 16:20:47 +03:00
parent 790eece361
commit 2a8b94136f
7 changed files with 101 additions and 1 deletions

View File

@@ -73,9 +73,25 @@ func NewApplication(cfg config.Config) (Application, error) {
return Application{}, fmt.Errorf("new rest server: %w", err)
}
var httpHandler http.Handler = server
if cfg.UI.Enabled {
ui := rest.NewUI(cfg.UI)
httpHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if ui.IsUIRequest(r) {
ui.ServeHTTP(w, r)
return
}
server.ServeHTTP(w, r)
})
}
httpServer := http.Server{
Addr: cfg.API.Address,
Handler: server,
Handler: httpHandler,
ReadTimeout: time.Second * 15,
ReadHeaderTimeout: time.Second * 5,
IdleTimeout: time.Second * 30,