Nexus/pkg/internal/http/api/index.go

50 lines
1.5 KiB
Go
Raw Normal View History

2024-10-19 14:36:33 +00:00
package api
import (
2024-11-13 14:26:54 +00:00
pkg "git.solsynth.dev/hypernet/nexus/pkg/internal"
"git.solsynth.dev/hypernet/nexus/pkg/internal/auth"
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
2024-10-20 16:05:40 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/internal/http/ws"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
2024-10-19 14:36:33 +00:00
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/proxy"
2024-10-19 14:36:33 +00:00
)
func MapAPIs(app *fiber.App) {
// Some built-in public-accessible APIs
2024-10-19 14:36:33 +00:00
wellKnown := app.Group("/.well-known").Name("Well Known")
{
wellKnown.Get("/", func(c *fiber.Ctx) error {
2024-11-13 14:26:54 +00:00
return c.JSON(fiber.Map{
"api_level": pkg.ApiLevel,
"version": pkg.AppVersion,
"status": true,
})
2024-10-19 14:36:33 +00:00
})
wellKnown.Get("/check-ip", getClientIP)
wellKnown.Get("/directory/services", listExistsService)
wellKnown.Get("/openid-configuration", func(c *fiber.Ctx) error {
service := directory.GetServiceInstanceByType(nex.ServiceTypeAuth)
if service == nil || service.HttpAddr == nil {
return fiber.ErrNotFound
}
return proxy.Do(c, *service.HttpAddr+"/.well-known/openid-configuration")
})
wellKnown.Get("/jwks", func(c *fiber.Ctx) error {
service := directory.GetServiceInstanceByType(nex.ServiceTypeAuth)
if service == nil || service.HttpAddr == nil {
return fiber.ErrNotFound
}
return proxy.Do(c, *service.HttpAddr+"/.well-known/jwks")
})
2024-10-19 14:36:33 +00:00
}
// Common websocket gateway
app.Get("/ws", auth.ValidatorMiddleware, websocket.New(ws.Listen))
2024-10-19 14:36:33 +00:00
2024-10-20 16:05:40 +00:00
app.All("/inv/:command", invokeCommand)
app.All("/cgi/:service/*", forwardService)
2024-10-19 14:36:33 +00:00
}