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"
|
2024-10-22 15:23:58 +00:00
|
|
|
"git.solsynth.dev/hypernet/nexus/pkg/internal/auth"
|
2024-11-23 10:23:10 +00:00
|
|
|
"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"
|
2024-11-23 10:23:10 +00:00
|
|
|
"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"
|
2024-11-23 10:23:10 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/proxy"
|
2024-10-19 14:36:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func MapAPIs(app *fiber.App) {
|
2024-10-20 07:22:19 +00:00
|
|
|
// 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)
|
2024-11-23 10:23:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-10-20 07:22:19 +00:00
|
|
|
// Common websocket gateway
|
2024-10-26 16:36:06 +00:00
|
|
|
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
|
|
|
}
|