You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
website/server/server.go

38 lines
675 B
Go

package server
import (
"log"
"git.phc.dm.unipi.it/phc/website/libs/sl"
"git.phc.dm.unipi.it/phc/website/server/config"
"github.com/gofiber/fiber/v2"
)
type Server struct{ Router *fiber.App }
var Slot = sl.NewSlot[*Server]()
var ApiRoutesHook = sl.NewHook[fiber.Router]()
func Configure(l *sl.ServiceLocator) (*Server, error) {
cfg, err := sl.Use(l, config.Slot)
if err != nil {
return nil, err
}
r := fiber.New(fiber.Config{})
r.Static("/assets", "./out/frontend/assets")
api := r.Group("/api")
if err := sl.UseHook(l, ApiRoutesHook, api); err != nil {
return nil, err
}
go func() {
log.Fatal(r.Listen(cfg.Host))
}()
return &Server{r}, nil
}