Refactor to support multiple server instances in shared library

This commit is contained in:
Pijus Kamandulis
2024-12-18 19:39:57 +02:00
parent 84c33e3c8e
commit 777034181f
34 changed files with 503 additions and 369 deletions

View File

@@ -4,15 +4,14 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/config"
)
func RegisterExplorerHandlers(router *gin.Engine) {
explorer := router.Group(config.Config.ExplorerBaseUrlLocation)
func (h *Handlers) RegisterExplorerHandlers(router *gin.Engine) {
explorer := router.Group(h.config.ExplorerBaseUrlLocation)
{
explorer.Use(func(ctx *gin.Context) {
if ctx.Param("filepath") == "/config.json" {
endpoint := fmt.Sprintf("https://%s:%d", config.Config.Host, config.Config.Port)
endpoint := fmt.Sprintf("https://%s:%d", h.config.Host, h.config.Port)
ctx.JSON(200, gin.H{
"BACKEND_ENDPOINT": endpoint,
"MONGO_BACKEND_ENDPOINT": endpoint,
@@ -25,8 +24,8 @@ func RegisterExplorerHandlers(router *gin.Engine) {
}
})
if config.Config.ExplorerPath != "" {
explorer.Static("/", config.Config.ExplorerPath)
if h.config.ExplorerPath != "" {
explorer.Static("/", h.config.ExplorerPath)
}
}
}