ytdl-web/web/serve.go

34 lines
747 B
Go

package web
import (
"fmt"
"github.com/gofiber/fiber/v2"
slogfiber "github.com/samber/slog-fiber"
"go.fifitido.net/ytdl-web/config"
"golang.org/x/exp/slog"
)
func Serve(cfg *config.Config) error {
engine := ViewsEngine()
app := fiber.New(fiber.Config{
Views: engine,
EnableTrustedProxyCheck: true,
TrustedProxies: cfg.HTTP.TrustedProxies,
DisableStartupMessage: true,
})
routes := &routes{}
logger := slog.With("module", "web")
app.Use(slogfiber.New(logger))
routes.Register(app)
listenAddr := fmt.Sprintf("%s:%d", cfg.HTTP.Listen, cfg.HTTP.Port)
logger.Info("Starting HTTP server", slog.String("host", cfg.HTTP.Listen), slog.Int("port", cfg.HTTP.Port))
return app.Listen(listenAddr)
}