Added vue frontend project, fixed swagger path

This commit is contained in:
2026-04-05 21:51:03 +03:00
parent 9d845c8899
commit 4902889401
35 changed files with 3810 additions and 475 deletions
+35 -1
View File
@@ -11,6 +11,8 @@ import (
"context"
"log"
"net/http"
"net/http/httptest"
"strings"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
@@ -34,9 +36,41 @@ func NewServer(cfg config.Config) *Server {
log.Fatal(err)
}
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
if cfg.OpenAPIEnabled {
router.GET("/openapi/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
openAPIEndpoint := cfg.OpenAPIEndpoint
if openAPIEndpoint == "" {
openAPIEndpoint = "/openapi"
}
swaggerHandler := ginSwagger.WrapHandler(swaggerFiles.Handler)
router.GET(openAPIEndpoint, func(c *gin.Context) {
recorder := httptest.NewRecorder()
proxyCtx, _ := gin.CreateTestContext(recorder)
proxyCtx.Request = c.Request.Clone(c.Request.Context())
proxyCtx.Request.URL.Path = openAPIEndpoint + "/index.html"
proxyCtx.Request.RequestURI = openAPIEndpoint + "/index.html"
swaggerHandler(proxyCtx)
for key, values := range recorder.Header() {
for _, value := range values {
c.Writer.Header().Add(key, value)
}
}
body := strings.Replace(
recorder.Body.String(),
"<head>",
"<head><base href=\""+openAPIEndpoint+"/\">",
1,
)
c.Status(recorder.Code)
_, _ = c.Writer.WriteString(body)
})
router.GET(openAPIEndpoint+"/*any", swaggerHandler)
}
apiV1 := router.Group("/api/v1")
+1 -1
View File
@@ -68,7 +68,7 @@ func Load() (Config, error) {
apiPort = "8000"
}
if openAPIEndpoint == "" {
openAPIEndpoint = "/docs"
openAPIEndpoint = "/openapi"
}
}