initial commit

This commit is contained in:
2023-01-31 02:40:19 +01:00
commit 552c004151
23 changed files with 1822 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
package dev
import (
"log"
"path"
"phc/website/services/server/routes"
"phc/website/sl"
"github.com/gofiber/fiber/v2"
)
type Dev struct {
HtmlRouteBindings map[string]string
}
func (m *Dev) Initialize(l *sl.ServiceLocator) error {
m.HtmlRouteBindings = map[string]string{}
router, err := sl.Use[*routes.Router](l)
if err != nil {
return err
}
router.Get("/api/dev/routes", func(c *fiber.Ctx) error {
return c.JSON(m.HtmlRouteBindings)
})
return nil
}
// UseVitePage this hook will link the provided "mountPoint" to the "frontendHtml" page
func UseVitePage[T any](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[*Dev](l)
if err != nil {
log.Fatal(err)
}
frontendPath := path.Join("./frontend/", frontendHtml)
dev.HtmlRouteBindings[mountPoint] = frontendPath
return func(c *fiber.Ctx) error {
return c.SendFile(frontendPath)
}
}