Dealer/pkg/internal/server/api/index.go

34 lines
758 B
Go
Raw Normal View History

2024-07-14 12:25:30 +00:00
package api
import (
"git.solsynth.dev/hydrogen/dealer/pkg/internal/server/exts"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
)
func MapAPIs(app *fiber.App) {
wellKnown := app.Group("/.well-known").Name("Well Known")
{
2024-07-26 17:10:26 +00:00
wellKnown.Get("/", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})
2024-07-14 12:25:30 +00:00
wellKnown.Get("/directory/services", listExistsService)
}
2024-07-26 17:10:26 +00:00
app.All("/cgi/:service/*", forwardServiceRequest)
2024-07-14 14:41:14 +00:00
2024-07-14 12:25:30 +00:00
api := app.Group("/api").Name("API")
{
api.Use(func(c *fiber.Ctx) error {
if err := exts.EnsureAuthenticated(c); err != nil {
return err
}
return c.Next()
}).Get("/ws", websocket.New(listenWebsocket))
api.All("/*", func(c *fiber.Ctx) error {
return fiber.ErrNotFound
})
}
}