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

37 lines
836 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-09-21 12:03:37 +00:00
wellKnown.Get("/check-ip", getClientIP)
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")
{
2024-08-19 07:36:57 +00:00
api.Get("/links/*", getLinkMeta)
2024-08-19 06:35:24 +00:00
2024-07-14 12:25:30 +00:00
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
})
}
}