Files
kouiz/internal/setup/http_server.go

40 lines
923 B
Go
Raw Normal View History

2025-06-10 21:09:58 +02:00
package setup
import (
"context"
2025-06-15 23:22:54 +02:00
"net/http"
2025-06-10 21:09:58 +02:00
"forge.cadoles.com/wpetit/kouiz/internal/config"
2025-06-15 23:22:54 +02:00
kouizHTTP "forge.cadoles.com/wpetit/kouiz/internal/http"
2025-06-10 21:09:58 +02:00
"github.com/pkg/errors"
)
2025-06-15 23:22:54 +02:00
func NewHTTPServerFromConfig(ctx context.Context, conf *config.Config) (*kouizHTTP.Server, error) {
2025-06-10 21:09:58 +02:00
// Configure Web UI handler
webui, err := NewWebUIHandlerFromConfig(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not configure webui handler from config")
}
2025-06-15 23:22:54 +02:00
// Configure API handler
api, err := NewAPIHandlerFromConfig(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not configure webui handler from config")
}
mux := http.NewServeMux()
mux.Handle("/", webui)
mux.Handle("/api/", http.StripPrefix("/api", api))
2025-06-10 21:09:58 +02:00
// Create HTTP server
2025-06-15 23:22:54 +02:00
server := kouizHTTP.NewServer(
mux,
kouizHTTP.WithAddress(conf.HTTP.Address),
kouizHTTP.WithBaseURL(conf.HTTP.BaseURL),
2025-06-10 21:09:58 +02:00
)
return server, nil
}