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/services/server/dev/dev.go

50 lines
984 B
Go

package dev
import (
"log"
"path"
"phc/website/services/server/routes"
"phc/website/sl"
"github.com/gofiber/fiber/v2"
)
var Slot = sl.NewSlot[*Dev]()
type Dev struct {
HtmlRouteBindings map[string]string
}
func New(l *sl.ServiceLocator) (*Dev, error) {
dev := &Dev{
map[string]string{},
}
router, err := sl.Use(l, routes.Api)
if err != nil {
return nil, err
}
router.Get("/dev/routes", func(c *fiber.Ctx) error {
return c.JSON(dev.HtmlRouteBindings)
})
return dev, nil
}
// UseVitePage this hook will link the provided "mountPoint" to the "frontendHtml" page
func UseVitePage(l *sl.ServiceLocator, mountPoint, frontendHtml string) func(c *fiber.Ctx) error {
log.Printf(`registering vite route %q for %q`, frontendHtml, mountPoint)
dev, err := sl.Use(l, Slot)
if err != nil {
log.Fatal(err)
}
dev.HtmlRouteBindings[mountPoint] = frontendHtml
return func(c *fiber.Ctx) error {
return c.SendFile(path.Join("./out/frontend/", frontendHtml))
}
}