From 4697556cac819c47d068819b9fc9c3b4ea84e279 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Thu, 14 Aug 2025 18:07:12 +0100 Subject: Merge confplanner-web and replace fiber with native net/http --- main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index d5706b0..b3c6165 100644 --- a/main.go +++ b/main.go @@ -3,16 +3,19 @@ package main import ( "fmt" "log/slog" + "net/http" "os" "github.com/LMBishop/confplanner/api" - config "github.com/LMBishop/confplanner/internal" + "github.com/LMBishop/confplanner/internal/config" "github.com/LMBishop/confplanner/pkg/calendar" "github.com/LMBishop/confplanner/pkg/database" "github.com/LMBishop/confplanner/pkg/favourites" "github.com/LMBishop/confplanner/pkg/ical" "github.com/LMBishop/confplanner/pkg/schedule" + "github.com/LMBishop/confplanner/pkg/session" "github.com/LMBishop/confplanner/pkg/user" + "github.com/LMBishop/confplanner/web" ) func main() { @@ -46,18 +49,25 @@ func run() error { } calendarService := calendar.NewService(pool) icalService := ical.NewService(favouritesService, scheduleService) + sessionService := session.NewMemoryStore() - app := api.NewServer(api.ApiServices{ + mux := http.NewServeMux() + api := api.NewServer(api.ApiServices{ UserService: userService, FavouritesService: favouritesService, ScheduleService: scheduleService, CalendarService: calendarService, IcalService: icalService, + SessionService: sessionService, }, c.BaseURL) + web := web.NewWebFileServer() - slog.Info("Server is listening", "host", c.Server.Host, "port", c.Server.Port) + mux.Handle("/api/", http.StripPrefix("/api", api)) + mux.Handle("/", web) - if err := app.Listen(fmt.Sprintf("%s:%s", c.Server.Host, c.Server.Port)); err != nil { + slog.Info("starting HTTP server", "host", c.Server.Host, "port", c.Server.Port) + + if err := http.ListenAndServe(fmt.Sprintf("%s:%s", c.Server.Host, c.Server.Port), mux); err != nil { return fmt.Errorf("failed to start server: %w", err) } -- cgit v1.2.3-70-g09d2